Module: RVGP::Utilities
- Included in:
- Base::Grid, Base::Grid, Base::Reconciler, Reconcilers::CsvReconciler
- Defined in:
- lib/rvgp/utilities.rb,
lib/rvgp/utilities/yaml.rb,
lib/rvgp/utilities/grid_query.rb more...
Overview
This module contains helper methods used throughout RVGP. These are just common codepaths, that have little in common, save for their general utility.
Defined Under Namespace
Instance Method Summary collapse
-
#months_through(date, ...) ⇒ Array<Date>
This returns each month in a series from the first date, to the last, in the provided array of dates.
-
#string_to_regex(str) ⇒ Regexp
Convert the provided string, into a Regexp.
Instance Method Details
#months_through(date, ...) ⇒ Array<Date>
This returns each month in a series from the first date, to the last, in the provided array of dates
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rvgp/utilities.rb', line 14 def months_through(*args) dates = args.flatten.uniq.sort ret = [] unless dates.empty? d = Date.new dates.first.year, dates.first.month, 1 # start_at while d <= Date.new(dates.last.year, dates.last.month, 1) # end_at ret << d d = d >> 1 end end ret end |
#string_to_regex(str) ⇒ Regexp
Convert the provided string, into a Regexp. Note that the the ixm suffixes are supported, unlike ruby’s Regexp.new(str) method
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rvgp/utilities.rb', line 32 def string_to_regex(str) if %r{\A/(.*)/([imx]?[imx]?[imx]?)\Z}.match str Regexp.new(::Regexp.last_match(1), ::Regexp.last_match(2).chars.map do |c| case c when 'i' then Regexp::IGNORECASE when 'x' then Regexp::EXTENDED when 'm' then Regexp::MULTILINE end end.reduce(:|)) end end |