lib/remi/cucumber/business_rules.rb in remi-0.2.6 vs lib/remi/cucumber/business_rules.rb in remi-0.2.7

- old
+ new

@@ -25,11 +25,11 @@ def is_formula?(arg) !base_regex.match(arg).nil? end def base_regex - @base_regex ||= /\A\*(.*)\*\Z/ + @base_regex ||= /\*(.*)\*/ end def formulas @formulas ||= Remi::Lookup::RegexSieve.new({ /(today|yesterday|tomorrow)/i => [:date_reference, :match_single_day], @@ -42,13 +42,18 @@ return form unless is_formula?(form) form_opt = formulas[form, :match] raise "Unknown formula #{form}" unless form_opt - if form_opt[:value][0] == :date_reference + to_replace = form.match(base_regex)[0] + replace_with = if form_opt[:value][0] == :date_reference date_reference(form_opt[:value][1], form_opt[:match]) + else + to_replace end + + form.gsub(to_replace, replace_with) end def date_reference(formula, captured) parsed = self.send("date_reference_#{formula}", *captured) @@ -242,9 +247,37 @@ # For debugging only def _df @data_obj.df end + + # Would like to have this return a new DataSubject and not a dataframe. + # Need more robust duping to make that feasible. + # Don't use results for anything more than size. + def where(field_name, operation) + @data_obj.df.where(@data_obj.df[field_name.symbolize(@data_obj.field_symbolizer)].recode { |v| operation.call(v) }) + end + + def where_is(field_name, value) + where(field_name, ->(v) { v == value }) + end + + def where_lt(field_name, value) + where(field_name, ->(v) { v.to_f < value.to_f }) + end + + def where_gt(field_name, value) + where(field_name, ->(v) { v.to_f > value.to_f }) + end + + def where_between(field_name, low_value, high_value) + where(field_name, ->(v) { v.to_f.between?(low_value.to_f, high_value.to_f) }) + end + + def where_in(field_name, list) + list_array = list.split(',').map { |v| v.strip } + where(field_name, ->(v) { list_array.include?(v) }) + end def stub_data @data_obj.stub_df if @data_obj.respond_to? :stub_df end