source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/check_uk_visa_flow.rb
Ruby
mit
179
main
14,296
class CheckUkVisaFlow < SmartAnswer::Flow def define flow = self content_id "dc1a1744-4089-43b3-b2e3-4e397b6b15b1" name "check-uk-visa" status :published additional_countries = UkbaCountry.all # Q1 country_select :what_passport_do_you_have?, additional_countries:, exclude_countries: Smar...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/state_pension_through_partner_flow.rb
Ruby
mit
179
main
3,411
class StatePensionThroughPartnerFlow < SmartAnswer::Flow def define content_id "42a41808-b338-4e4b-a703-47195982f4c8" name "state-pension-through-partner" status :published # Q1 radio :what_is_your_marital_status? do option :married option :widowed option :divorced on_res...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_your_redundancy_pay_flow.rb
Ruby
mit
179
main
235
class CalculateYourRedundancyPayFlow < SmartAnswer::Flow def define content_id "d2786d90-20fa-467e-ac4a-ff51dcd01b4f" name "calculate-your-redundancy-pay" status :published append(RedundancyPayFlow.build) end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_agricultural_holiday_entitlement_flow.rb
Ruby
mit
179
main
2,492
class CalculateAgriculturalHolidayEntitlementFlow < SmartAnswer::Flow def define content_id "8834bc7c-7ac7-4d45-8a57-1d5a5dcd70a0" name "calculate-agricultural-holiday-entitlement" status :published radio :work_the_same_number_of_days_each_week? do option "same-number-of-days" option "dif...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/maternity_paternity_calculator_flow.rb
Ruby
mit
179
main
1,172
class MaternityPaternityCalculatorFlow < SmartAnswer::Flow def define content_id "05d5412d-455b-485e-a570-020c9176a46e" name "maternity-paternity-calculator" status :published ## Q1 radio :what_type_of_leave? do option :maternity option :paternity option :adoption on_resp...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/additional_commodity_code_flow.rb
Ruby
mit
179
main
4,085
class AdditionalCommodityCodeFlow < SmartAnswer::Flow def define content_id "bfda3b4f-166b-48e7-9aaf-21bfbd606207" name "additional-commodity-code" status :published # Q1 radio :how_much_starch_glucose? do option 0 option 5 option 25 option 50 option 75 on_re...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/simplified_expenses_checker_flow.rb
Ruby
mit
179
main
8,174
class SimplifiedExpensesCheckerFlow < SmartAnswer::Flow def define content_id "8ad76560-8a27-42ee-9a99-8aaa8f0109a5" name "simplified-expenses-checker" status :published # Q1 - vehicle expense radio :vehicle_expense? do option :car option :van option :motorcycle option :no...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/register_a_death_flow.rb
Ruby
mit
179
main
1,551
class RegisterADeathFlow < SmartAnswer::Flow def define content_id "9e3af3d4-f044-4ac5-830e-d604d701695b" name "register-a-death" status :published # Q1 radio :where_did_the_death_happen? do on_response do |response| self.calculator = SmartAnswer::Calculators::RegisterADeathCalculat...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/inherits_someone_dies_without_will_flow.rb
Ruby
mit
179
main
10,186
class InheritsSomeoneDiesWithoutWillFlow < SmartAnswer::Flow def define content_id "1f75de31-1f07-4c68-b1ab-8330b1ee8670" name "inherits-someone-dies-without-will" status :published # The case & if blocks in this file are organised to be read in the same order # as the flow chart rather than to m...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/estimate_self_assessment_penalties_flow.rb
Ruby
mit
179
main
1,695
class EstimateSelfAssessmentPenaltiesFlow < SmartAnswer::Flow def define content_id "32b54f44-fca1-4480-b13b-ddeb0b0238e1" name "estimate-self-assessment-penalties" status :published radio :which_year? do option :"2018-19" option :"2019-20" option :"2020-21" option :"2021-22" ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/minimum_wage_calculator_employers_flow.rb
Ruby
mit
179
main
238
class MinimumWageCalculatorEmployersFlow < SmartAnswer::Flow def define content_id "cc25f6ca-0553-4400-9dba-a43294fee84b" name "minimum-wage-calculator-employers" status :published append MinimumWageFlow.build end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_married_couples_allowance_flow.rb
Ruby
mit
179
main
3,556
class CalculateMarriedCouplesAllowanceFlow < SmartAnswer::Flow def define content_id "e04dc5fe-9a31-4229-9de9-884dd0c0a8ce" name "calculate-married-couples-allowance" status :published radio :were_you_or_your_partner_born_on_or_before_6_april_1935? do option :yes option :no next_no...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_statutory_sick_pay_flow.rb
Ruby
mit
179
main
8,960
class CalculateStatutorySickPayFlow < SmartAnswer::Flow def define content_id "1c676a9e-0424-4ebb-bab8-d8cb8d2fc6f8" name "calculate-statutory-sick-pay" status :published # Question 1 checkbox_question :is_your_employee_getting? do option :statutory_maternity_pay option :maternity_al...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/check_benefits_financial_support_flow.rb
Ruby
mit
179
main
4,978
class CheckBenefitsFinancialSupportFlow < SmartAnswer::Flow def define name "check-benefits-financial-support" content_id "2de3ab4d-e2af-4803-b2e4-9972da293b00" status :published radio :where_do_you_live do option :england option :wales option :scotland option :"northern-irela...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_employee_redundancy_pay_flow.rb
Ruby
mit
179
main
243
class CalculateEmployeeRedundancyPayFlow < SmartAnswer::Flow def define content_id "a5b52037-1712-4544-a3d1-a352ce8a8287" name "calculate-employee-redundancy-pay" status :published append(RedundancyPayFlow.build) end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/part_year_profit_tax_credits_flow.rb
Ruby
mit
179
main
2,944
class PartYearProfitTaxCreditsFlow < SmartAnswer::Flow def define name "part-year-profit-tax-credits" status :published content_id "de6723a5-7256-4bfd-aad3-82b04b06b73e" date_question :when_did_your_tax_credits_award_end? do on_response do |response| self.calculator = SmartAnswer::Calc...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/next_steps_for_your_business_flow.rb
Ruby
mit
179
main
3,036
class NextStepsForYourBusinessFlow < SmartAnswer::Flow def define name "next-steps-for-your-business" content_id "4d7751b5-d860-4812-aa36-5b8c57253ff2" status :published response_store :query_parameters additional_parameters %i[ct crn] # =======================================================...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/uk_benefits_abroad_flow.rb
Ruby
mit
179
main
27,895
class UkBenefitsAbroadFlow < SmartAnswer::Flow def define content_id "e1eaf183-1211-4fd7-b439-5c94498814ef" name "uk-benefits-abroad" status :published exclude_countries = %w[british-antarctic-territory french-guiana guadeloupe holy-see martinique mayotte reunion st-maarten] additional_countries ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/check_building_safety_costs_flow.rb
Ruby
mit
179
main
3,840
class CheckBuildingSafetyCostsFlow < SmartAnswer::Flow def define name "check-building-safety-costs" content_id "29355604-e9a1-499a-9b0c-18abd833f02e" status :published radio :building_over_11_metres? do option :yes option :no next_node do |response| if response == "yes" ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/maternity_paternity_pay_leave_flow.rb
Ruby
mit
179
main
23,679
class MaternityPaternityPayLeaveFlow < SmartAnswer::Flow def define content_id "1f6b4ecc-ce2c-488a-b9c7-b78b3bba5598" name "maternity-paternity-pay-leave" status :published radio :two_carers do option "yes" option "no" on_response do |response| self.calculator = SmartAnswer...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/towing_rules_flow.rb
Ruby
mit
179
main
7,513
class TowingRulesFlow < SmartAnswer::Flow def define content_id "7bab842c-a9aa-4369-b162-4e3e2a475245" name "towing-rules" status :published ## Cars and light vehicles ## ## Q1 radio :towing_vehicle_type? do option "car-or-light-vehicle" option "medium-sized-vehicle" opt...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/all_smart_answer_questions_flow.rb
Ruby
mit
179
main
2,650
# not a real smart answer, this is here to make testing and changing all front-end elements easier class AllSmartAnswerQuestionsFlow < SmartAnswer::Flow def define content_id "92661afb-63ce-4ded-b06e-cf6288c0d629" name "all-smart-answer-questions" status :draft additional_countries = [OpenStruct.new(...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/plan_adoption_leave_flow.rb
Ruby
mit
179
main
1,017
class PlanAdoptionLeaveFlow < SmartAnswer::Flow def define content_id "b0e80c8b-d19f-4a50-82f4-71ab08f88207" name "plan-adoption-leave" status :published date_question :child_match_date? do on_response do |response| self.calculator = SmartAnswer::Calculators::PlanAdoptionLeave.new ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/child_benefit_tax_calculator_flow.rb
Ruby
mit
179
main
5,093
class ChildBenefitTaxCalculatorFlow < SmartAnswer::Flow def define name "child-benefit-tax-calculator" content_id "0e1de8f1-9909-4e45-a6a3-bffe95470275" status :published # Q1 value_question :how_many_children?, parse: Integer do on_response do |response| self.calculator = SmartAnsw...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/student_finance_calculator_flow.rb
Ruby
mit
179
main
5,482
class StudentFinanceCalculatorFlow < SmartAnswer::Flow def define content_id "434b6eb5-33c8-4300-aba3-f5ead58600b8" name "student-finance-calculator" status :published # Q1 radio :when_does_your_course_start? do option :"2025-2026" option :"2026-2027" option :"2027-2028" ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/vat_payment_deadlines_flow.rb
Ruby
mit
179
main
1,777
class VatPaymentDeadlinesFlow < SmartAnswer::Flow def define content_id "dfa9a5c3-d52e-479c-8505-855f475dc338" name "vat-payment-deadlines" status :published date_question :when_does_your_vat_accounting_period_end? do default_day { -1 } on_response do self.calculator = SmartAnswe...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_inheritance_tax_interest_flow.rb
Ruby
mit
179
main
1,218
class CalculateInheritanceTaxInterestFlow < SmartAnswer::Flow def define name "calculate-inheritance-tax-interest" content_id "f066bf22-70c1-4085-986b-39c585a138a3" status :published date_question :start_date_for_interest? do validate :error_start_date_too_early do |response| response >...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/am_i_getting_minimum_wage_flow.rb
Ruby
mit
179
main
221
class AmIGettingMinimumWageFlow < SmartAnswer::Flow def define content_id "111e006d-2b22-4b1f-989a-56bb61355d68" name "am-i-getting-minimum-wage" status :published append MinimumWageFlow.build end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/calculate_your_holiday_entitlement_flow.rb
Ruby
mit
179
main
10,082
class CalculateYourHolidayEntitlementFlow < SmartAnswer::Flow def define content_id "deedf6f8-389b-4b34-a5b1-faa9ef909a70" name "calculate-your-holiday-entitlement" status :published # Q1 radio :regular_or_irregular_hours? do option "irregular-hours-and-part-year" option "regular" ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/state_pension_age_flow.rb
Ruby
mit
179
main
1,555
class StatePensionAgeFlow < SmartAnswer::Flow def define content_id "5491c439-1c83-4044-80d3-32cc3613b739" name "state-pension-age" status :published # Q1 radio :which_calculation? do option :age option :bus_pass on_response do |response| self.which_calculation = respon...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/maternity_paternity_calculator_flow/shared_adoption_maternity_paternity_flow.rb
Ruby
mit
179
main
3,228
class MaternityPaternityCalculatorFlow < SmartAnswer::Flow class SharedAdoptionMaternityPaternityFlow < SmartAnswer::Flow def define payment_options = SmartAnswer::Calculators::MaternityPayCalculator.payment_options # This question is being used in: # QM8 in MaternityCalculatorFlow # QP16...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/maternity_paternity_calculator_flow/paternity_calculator_flow.rb
Ruby
mit
179
main
14,216
class MaternityPaternityCalculatorFlow < SmartAnswer::Flow class PaternityCalculatorFlow < SmartAnswer::Flow def define days_of_the_week = SmartAnswer::Calculators::MaternityPayCalculator::DAYS_OF_THE_WEEK ## QP1 radio :where_does_the_employee_live? do option "england" option "s...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/maternity_paternity_calculator_flow/adoption_calculator_flow.rb
Ruby
mit
179
main
7,920
class MaternityPaternityCalculatorFlow < SmartAnswer::Flow class AdoptionCalculatorFlow < SmartAnswer::Flow def define radio :taking_paternity_or_maternity_leave_for_adoption? do option :paternity option :maternity next_node do |response| case response when "pate...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/maternity_paternity_calculator_flow/maternity_calculator_flow.rb
Ruby
mit
179
main
8,102
class MaternityPaternityCalculatorFlow < SmartAnswer::Flow class MaternityCalculatorFlow < SmartAnswer::Flow def define days_of_the_week = SmartAnswer::Calculators::MaternityPayCalculator::DAYS_OF_THE_WEEK ## QM1 date_question :baby_due_date_maternity? do on_response do |response| ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/shared/redundancy_pay_flow.rb
Ruby
mit
179
main
2,179
class RedundancyPayFlow < SmartAnswer::Flow def define date_question :date_of_redundancy? do from { SmartAnswer::Calculators::RedundancyCalculator.first_selectable_date } to { SmartAnswer::Calculators::RedundancyCalculator.last_selectable_date } on_response do |response| self.rates = Sm...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/flows/shared/minimum_wage_flow.rb
Ruby
mit
179
main
8,860
class MinimumWageFlow < SmartAnswer::Flow def define # Q1 radio :what_would_you_like_to_check? do option "current_payment" option "past_payment" on_response do |response| self.calculator = SmartAnswer::Calculators::MinimumWageCalculator.new(past_or_current_payment: response) ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/controllers/flow_controller.rb
Ruby
mit
179
main
1,925
class FlowController < ApplicationController include FlowHelper before_action :set_cache_headers before_action :redirect_path_based_flows, except: :landing def landing @presenter = FlowPresenter.new(flow, nil) @title = @presenter.title render @presenter.start_node.view_template_path, formats: [:h...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/controllers/smart_answers_controller.rb
Ruby
mit
179
main
2,100
class SmartAnswersController < ApplicationController before_action :find_smart_answer, except: %w[index] before_action :redirect_response_to_canonical_path, only: %w[show] before_action :content_item, except: %w[index] content_security_policy only: :visualise do |p| # The script used to render the visualis...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
app/controllers/application_controller.rb
Ruby
mit
179
main
1,154
class ApplicationController < ActionController::Base rescue_from GdsApi::TimedOutException, with: :error_503 rescue_from GdsApi::HTTPForbidden, with: :error_403 rescue_from ActionController::UnknownFormat, with: :error_404 rescue_from SmartAnswer::FlowRegistry::NotFound, SmartAnswer::InvalidTransition, with: :e...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/list_validator.rb
Ruby
mit
179
main
337
class ListValidator def self.call(constraint: {}, test: []) test.map!(&:to_sym) new(constraint.keys).all_valid?(test) end attr_reader :list def initialize(list) @list = list end def all_valid?(elements) return false unless elements.present? && elements.is_a?(Array) (elements - list)....
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/response_store.rb
Ruby
mit
179
main
493
class ResponseStore def initialize(responses: {}, user_response_keys: [], additional_keys: []) @user_response_keys = user_response_keys @additional_keys = additional_keys @store = responses end def all @store end def add(key, value) all[key] = value end def get(key) all[key] e...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/method_missing_object.rb
Ruby
mit
179
main
881
class MethodMissingObject def initialize(method, parent_method: nil, blank_to_s: false, overrides: {}) @method = method @parent_method = parent_method @blank_to_s = blank_to_s @overrides = overrides end # rubocop:disable Style/MissingRespondToMissing def method_missing(method, *_args, &_block) ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/broken_link_report.rb
Ruby
mit
179
main
1,702
class BrokenLinkReport def self.for_erb_files_at(flows_root_path) new(flows_root_path).summary_report end attr_reader :flows_root_path def initialize(flows_root_path) @flows_root_path = flows_root_path end def folder_paths path_to_items_within_root_folder = File.join(flows_root_path, "*") ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/state_pension_date.rb
Ruby
mit
179
main
298
StatePensionDate = Struct.new(:gender, :start_date, :end_date, :pension_date) do def match?(dob, sex) same_gender?(sex) && born_in_range?(dob) end def same_gender?(sex) [sex, :both].include?(gender) end def born_in_range?(dob) dob >= start_date && dob <= end_date end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/session_response_store.rb
Ruby
mit
179
main
438
class SessionResponseStore < ResponseStore def initialize(flow_name:, session:, user_response_keys: [], additional_keys: []) @flow_name = flow_name super(responses: session, user_response_keys:, additional_keys:) end def all @store[@flow_name] = {} if @store[@flow_name].nil? @...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/link_checker.rb
Ruby
mit
179
main
1,168
class LinkChecker attr_reader :texts def initialize(texts) @texts = texts end def urls @urls ||= extract_urls end def report return if urls.blank? @report ||= generate_report end private def extract_urls return Set[] if texts.blank? urls = texts.map { |text| URI.extract(te...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/state_pension_date_query.rb
Ruby
mit
179
main
3,239
require_relative "state_pension_date" StatePensionDateQuery = Struct.new(:dob, :gender) do def self.state_pension_date(dob, gender) new(dob, gender).find_date end def self.pension_credit_date(dob) # Pension credit age calculation for all genders is equivalent # to the state pension date calculation f...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/query_parameters_response_store.rb
Ruby
mit
179
main
316
class QueryParametersResponseStore < ResponseStore def initialize(query_parameters:, user_response_keys:, additional_keys:) allowable_keys = user_response_keys + additional_keys super(responses: query_parameters.slice(*allowable_keys), user_response_keys:, additional_keys:) end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/working_days.rb
Ruby
mit
179
main
1,188
require "gds_api/base" require "gds_api/json_client" class WorkingDays WEEKDAYS = (1..5) BANK_HOLIDAYS_URL = "https://www.gov.uk/bank-holidays.json".freeze def initialize(days) @days = days end def after(date) days = @days while days.positive? || !workday?(date) date += 1.day days -...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/tasks/testing.rake
Ruby
mit
179
main
432
require "rake/testtask" Rake::TestTask.new("test:integration:engine") do |t| t.libs << "test" t.test_files = Dir["test/integration/engine/**/*_test.rb"] end Rake::TestTask.new("test:integration:flows") do |t| t.libs << "test" t.test_files = Dir["test/integration/flows/**/*_test.rb"] end Rake::TestTask.new("t...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/tasks/links.rake
Ruby
mit
179
main
241
SMART_ANSWER_FLOW_PATH = Rails.root.join("app/flows") namespace :links do desc "Checks all URLs within Smart Answers for errors." task report: :environment do puts BrokenLinkReport.for_erb_files_at(SMART_ANSWER_FLOW_PATH) end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/tasks/publishing_api.rake
Ruby
mit
179
main
2,213
namespace :publishing_api do desc "Sync all smart answers with the Publishing API" task sync_all: [:environment] do flows = SmartAnswer::FlowRegistry.instance.flows ContentItemSyncer.new.sync(flows) end desc "Sync a single smart answer with the Publishing API" task :sync, %i[slug] => [:environment] d...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/generators/smart_answer/smart_answer_generator.rb
Ruby
mit
179
main
1,125
class SmartAnswerGenerator < Rails::Generators::NamedBase source_root File.expand_path("templates", __dir__) def copy_flow filename = "app/flows/#{name.underscore}_flow.rb" copy_file "flow.rb", filename gsub_file filename, "SmartAnswerName", name.camelize inject_into_file filename, after: "def de...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/generators/smart_answer/templates/calculator.rb
Ruby
mit
179
main
538
# ====================================================================== # Allows access to the quesion answers provides custom validations # and calculations, and other supporting methods. # ====================================================================== module SmartAnswer::Calculators class SmartAnswerNameC...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/generators/smart_answer/templates/flow.rb
Ruby
mit
179
main
1,309
# ====================================================================== # The flow logic. # ====================================================================== class SmartAnswerNameFlow < SmartAnswer::Flow def define # ====================================================================== # Available inpu...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/rate_dates_helper.rb
Ruby
mit
179
main
712
module SmartAnswer module RateDatesHelper def last_year_text(rates_file) "#{last_year(rates_file)[:start_date].strftime('%B %Y')} to #{last_year(rates_file)[:end_date].strftime('%B %Y')}" end def last_year_end_text(rates_file) last_year(rates_file)[:end_date].strftime("%B %Y").to_s end ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/node.rb
Ruby
mit
179
main
2,634
require "active_support/inflector" module SmartAnswer class Node PRESENTER_CLASS = NodePresenter class NextNodeUndefined < StandardError; end attr_accessor :flow attr_reader :name, :view_template_path def initialize(flow, name, &block) @flow = flow @name = name @template_name...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/formatting_helper.rb
Ruby
mit
179
main
978
module SmartAnswer module FormattingHelper include ActionView::Helpers::NumberHelper def format_money(amount, pounds_only: false) amount = extract_number(amount) if show_in_pence?(amount) number_to_currency(amount * 100, precision: 0, unit: "p", format: "%n%u") else ignore_p...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/money.rb
Ruby
mit
179
main
1,104
require "bigdecimal" module SmartAnswer class Money include Comparable delegate :to_f, :to_s, :*, :+, :-, :/, to: :value attr_reader :value def initialize(raw_input) input = self.class.parse(raw_input) self.cl...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/state_resolver.rb
Ruby
mit
179
main
2,451
module SmartAnswer class StateResolver def initialize(flow) @flow = flow end def state_from_response_store(response_store, requested_node = nil) start_state = State.new(@flow.questions.first.name) start_state.instance_eval(&@flow.setup) if @flow.setup @flow.additional_parameters....
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/method_invocations_parser.rb
Ruby
mit
179
main
935
require "parser/current" module SmartAnswer class MethodInvocationsParser class Processor < Parser::AST::Processor attr_reader :invocations def initialize(methods) super() @methods = methods @invocations = [] end def on_send(node) _receiver_node, method_n...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/salary.rb
Ruby
mit
179
main
1,119
module SmartAnswer class Salary include Comparable attr_reader :amount, :period def initialize(amount_or_options = {}, period = nil) if amount_or_options.is_a?(Hash) amount = amount_or_options[:amount] period = amount_or_options[:period] elsif amount_or_options.to_s.match(/^[...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/year_range.rb
Ruby
mit
179
main
646
module SmartAnswer class YearRange < DateRange def self.resetting_on(date) YearRangeWithFixedStartDate.new(date) end def self.tax_year resetting_on("6 April") end def self.agricultural_holiday_year resetting_on("1 October") end def initialize(begins_on:) ends_on ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/flow_registry.rb
Ruby
mit
179
main
710
module SmartAnswer class FlowRegistry class NotFound < StandardError; end FLOW_DIR = Rails.root.join("app/flows") attr_reader :flows, :load_path def self.instance @instance ||= new end def self.reset_instance(options = {}) @instance = new(options) end def initialize(opt...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/date_helper.rb
Ruby
mit
179
main
400
module SmartAnswer module DateHelper def next_saturday(date) (1..7).each do |inc| return date + inc if (date + inc).saturday? end end def formatted_date(date) date.strftime("%d %B %Y") end def self.current_day if ENV["RATES_QUERY_DATE"] Date.parse(ENV["RAT...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/overseas_passports_helper.rb
Ruby
mit
179
main
232
module SmartAnswer module OverseasPassportsHelper def timing_prefix(optimistic_processing_time) if optimistic_processing_time "should take" else "will take **at least**" end end end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/state.rb
Ruby
mit
179
main
917
require "ostruct" module SmartAnswer class State < OpenStruct def initialize(start_node_name) super(current_node_name: start_node_name, accepted_responses: {}, current_response: nil, error: nil) end def method_missing(method_name, *args) if respond_to_miss...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/year_range_with_fixed_start_date.rb
Ruby
mit
179
main
825
module SmartAnswer class YearRangeWithFixedStartDate def initialize(start_date) start_date = Date.parse(start_date.to_s) @start_day = start_date.day @start_month = start_date.month end def starting_in(start_year) # To handle the very rare case where we hit a leap year # Prev...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/date_range.rb
Ruby
mit
179
main
3,855
module SmartAnswer class DateRange include SmartAnswer::DateHelper include ActionView::Helpers::TextHelper EARLIEST_DATE = -Date::Infinity.new LATEST_DATE = Date::Infinity.new ComparableDate = Struct.new(:date) class ComparableDate include Comparable def <=>(other) if da...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/outcome.rb
Ruby
mit
179
main
247
module SmartAnswer class Outcome < Node PRESENTER_CLASS = OutcomePresenter def outcome? true end def transition(*_args) raise InvalidTransition, "can't transition once an outcome has been reached" end end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/next_node_block.rb
Ruby
mit
179
main
949
require "method_source" module SmartAnswer module NextNodeBlock class PermittedNodeKey < SimpleDelegator delegate :nil?, to: :__getobj__ end def self.permitted?(node) node.is_a?(PermittedNodeKey) end module InstanceMethods def question(key) PermittedNodeKey.new(key) ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/erb_renderer.rb
Ruby
mit
179
main
1,220
module SmartAnswer class ErbRenderer def initialize(template_directory:, template_name:, locals: {}, helpers: []) @template_directory = template_directory @template_name = template_name @locals = locals default_view_paths = ActionController::Base.view_paths.paths.map(&:to_s) lookup_c...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/flow.rb
Ruby
mit
179
main
3,131
require "ostruct" module SmartAnswer class Flow attr_reader :nodes attr_writer :status def self.build(&block) flow = new if block_given? flow.instance_eval(&block) else flow.define end flow end def initialize @nodes = [] @additional_pa...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/date_of_birth.rb
Ruby
mit
179
main
548
module SmartAnswer class DateOfBirth def initialize(date_of_birth) @date_of_birth = date_of_birth end def birthday(year: Time.zone.today.year) month = @date_of_birth.month day = @date_of_birth.day if !Date.new(year).leap? && month == 2 && day == 29 month = 3 day = ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/radio.rb
Ruby
mit
179
main
930
module SmartAnswer module Question class Radio < Base PRESENTER_CLASS = RadioQuestionPresenter attr_accessor :option_keys, :options_block def initialize(flow, name, &block) @option_keys = [] @options_block = nil super end def option(key) @option_key...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/date.rb
Ruby
mit
179
main
3,046
require "date" module SmartAnswer module Question class Date < Base PRESENTER_CLASS = DateQuestionPresenter def from(&block) if block_given? @from_func = block else @from_func && @from_func.call end end def to(&block) if block_given? ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/checkbox.rb
Ruby
mit
179
main
1,751
module SmartAnswer module Question class Checkbox < Base PRESENTER_CLASS = CheckboxQuestionPresenter NONE_OPTION = "none".freeze attr_accessor :option_keys, :options_block def initialize(flow, name, &block) @option_keys = [] @options_block = nil super end ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/salary.rb
Ruby
mit
179
main
214
module SmartAnswer module Question class Salary < Base PRESENTER_CLASS = SalaryQuestionPresenter def parse_input(raw_input) SmartAnswer::Salary.new(raw_input) end end end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/money.rb
Ruby
mit
179
main
211
module SmartAnswer module Question class Money < Base PRESENTER_CLASS = MoneyQuestionPresenter def parse_input(raw_input) SmartAnswer::Money.new(raw_input) end end end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/base.rb
Ruby
mit
179
main
1,308
module SmartAnswer module Question class Base < Node PRESENTER_CLASS = QuestionPresenter def initialize(flow, name, &block) @on_response_block = nil @validations = [] super end def validate(message = nil, &block) @validations << [message, block] end ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/value.rb
Ruby
mit
179
main
784
module SmartAnswer module Question class Value < Base PRESENTER_CLASS = ValueQuestionPresenter def initialize(flow, name, options = {}, &block) @parse = options[:parse] super(flow, name, &block) end def parse_input(raw_input) if @parse == Integer begin ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/postcode.rb
Ruby
mit
179
main
352
module SmartAnswer module Question class Postcode < Base def parse_input(raw_input) postcode = UKPostcode.parse(raw_input) raise InvalidResponse, :error_postcode_invalid unless postcode.valid? raise InvalidResponse, :error_postcode_incomplete unless postcode.full? postcode.t...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/year.rb
Ruby
mit
179
main
1,559
require "date" module SmartAnswer module Question class Year < Base PRESENTER_CLASS = YearQuestionPresenter def from(&block) if block_given? @from_func = block else @from_func && @from_func.call end end def to(&block) if block_given? ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/question/country_select.rb
Ruby
mit
179
main
1,326
module SmartAnswer module Question class CountrySelect < Base PRESENTER_CLASS = CountrySelectQuestionPresenter def initialize(flow, name, options = {}, &block) @exclude_countries = options.delete(:exclude_countries) @include_uk = options.delete(:include_uk) @additional_countri...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/erb_renderer/question_options_helper.rb
Ruby
mit
179
main
316
module SmartAnswer module ErbRenderer::QuestionOptionsHelper def options(new_options = nil) @options = new_options || @options || {} end def hide_caption(hide_caption = false) # rubocop:disable Style/OptionalBooleanParameter @hide_caption = hide_caption || @hide_caption end end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/erb_renderer/format_capture_helper.rb
Ruby
mit
179
main
1,738
module SmartAnswer module ErbRenderer::FormatCaptureHelper TEXT_CONTENT = [ :title, :meta_description, :label, :suffix_label, /^error_/, ].freeze def text_for(name, &block) content = capture_content(&block) content = strip_leading_spaces(content) content = ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/maternity_pay_calculator.rb
Ruby
mit
179
main
13,890
require_relative "../date_helper" module SmartAnswer::Calculators class MaternityPayCalculator include SmartAnswer::DateHelper attr_reader :due_date, :expected_week, :qualifying_week, :employment_start, :notice_of_leave_deadline, ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/rates_query.rb
Ruby
mit
179
main
1,248
module SmartAnswer::Calculators class RatesQuery def self.from_file(rates_filename, load_path: "config/smart_answers/rates") rates_data_path = Rails.root.join(load_path, "#{rates_filename}.yml") rates_yaml = YAML.load_file(rates_data_path, permitted_classes: [Date, Symbol]) rates_data = rates_ya...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/vat_payment_deadlines.rb
Ruby
mit
179
main
1,998
require "working_days" module SmartAnswer::Calculators class VatPaymentDeadlines attr_accessor :payment_method, :period_end_date def last_payment_date case payment_method when "direct-debit" payment_date = end_of_month_after(period_end_date) + 7.days payment_date -= 1 until payme...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/check_building_safety_costs_calculator.rb
Ruby
mit
179
main
3,823
module SmartAnswer::Calculators class CheckBuildingSafetyCostsCalculator include ActionView::Helpers::NumberHelper attr_accessor :purchased_pre_or_post_february_2022, :year_of_purchase, :value_of_property, :live_in_london, :shared_owners...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/plan_maternity_leave.rb
Ruby
mit
179
main
1,486
module SmartAnswer::Calculators class PlanMaternityLeave include ActionView::Helpers::DateHelper include SmartAnswer::DateHelper attr_reader :formatted_due_date, :formatted_start_date, :leave_earliest_start_date def initialize(options = {}) @due_date = Date.parse(options[:due_date]) due_...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/paternity_adoption_pay_calculator.rb
Ruby
mit
179
main
1,128
module SmartAnswer::Calculators class PaternityAdoptionPayCalculator < PaternityPayCalculator delegate :adoption_placement_date, :adoption_placement_date=, :adoption_qualifying_start, :a_notice_leave, :matched_week, :a_employment_start, ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/maternity_paternity_pay_leave_calculator.rb
Ruby
mit
179
main
5,325
module SmartAnswer::Calculators class MaternityPaternityPayLeaveCalculator include ActiveModel::Model attr_accessor :two_carers, :where_does_the_mother_partner_live, :due_date, :employment_status_of_mother, :employment_status_of_partner,...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/student_finance_calculator.rb
Ruby
mit
179
main
6,956
module SmartAnswer module Calculators class StudentFinanceCalculator attr_accessor :course_start, :household_income, :residence, :course_type, :course_studied, :part_time_credits, :full_ti...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/married_couples_allowance_calculator.rb
Ruby
mit
179
main
2,052
module SmartAnswer::Calculators class MarriedCouplesAllowanceCalculator attr_accessor :marriage_or_civil_partnership_before_5_december_2005, :birth_date, :income, :gross_pension_contributions, :net_pension_contributions, :gi...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/inherits_someone_dies_without_will_calculator.rb
Ruby
mit
179
main
1,263
module SmartAnswer::Calculators class InheritsSomeoneDiesWithoutWillCalculator attr_accessor :region, :next_steps, :partner, :estate_over_250000, :date_of_death, :children, :parents, :siblings, :siblings_including_mixed_parents, :grandparents, :aunts_or_uncles, :half_siblings, ...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/self_assessment_penalties.rb
Ruby
mit
179
main
10,176
require "ostruct" module SmartAnswer::Calculators class SelfAssessmentPenalties < OpenStruct ONLINE_FILING_DEADLINE_YEAR = SmartAnswer::YearRange.resetting_on("31 January").freeze ONLINE_FILING_DEADLINE_YEAR_FEB = SmartAnswer::YearRange.resetting_on("28 February").freeze OFFLINE_FILING_DEADLINE_YEAR = Sm...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/check_benefits_financial_support_calculator.rb
Ruby
mit
179
main
11,701
module SmartAnswer::Calculators class CheckBenefitsFinancialSupportCalculator attr_accessor :where_do_you_live, :over_state_pension_age, :are_you_working, :how_many_paid_hours_work, :disability_or_health_condition, :disabili...
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/personal_allowance_calculator.rb
Ruby
mit
179
main
317
module SmartAnswer module Calculators class PersonalAllowanceCalculator delegate :personal_allowance, to: :rates delegate :income_limit_for_personal_allowances, to: :rates private def rates @rates ||= RatesQuery.from_file("personal_allowance").rates end end end end
github
alphagov/smart-answers
https://github.com/alphagov/smart-answers
lib/smart_answer/calculators/part_year_profit_tax_credits_calculator.rb
Ruby
mit
179
main
2,113
module SmartAnswer module Calculators class PartYearProfitTaxCreditsCalculator include ActiveModel::Model attr_accessor :tax_credits_award_ends_on, :accounts_end_month_and_day, :taxable_profit, :stopped_trading, :started_...