module ScopeMethods::ClassMethods
Public Instance Methods
build_scope_string(ayear, amonth)
click to toggle source
# File lib/scope_methods.rb, line 13 def build_scope_string ayear, amonth amonth = amonth.to_i ayear = ayear.to_i raise "Invalid Scope string #{ayear} #{amonth}" unless valid_month?(amonth) and valid_year?(ayear) amonth < 10 ? "#{ayear}0#{amonth.to_i}" : "#{ayear}#{amonth.to_i}" end
date_to_scope(date)
click to toggle source
# File lib/scope_methods.rb, line 33 def date_to_scope date Scope.new(build_scope_string date.year, date.month) end
make_scope(ayear, amonth)
click to toggle source
# File lib/scope_methods.rb, line 8 def make_scope ayear, amonth scope_string = Scope.build_scope_string ayear, amonth Scope.new scope_string end
month(scope_value)
click to toggle source
# File lib/scope_methods.rb, line 29 def month scope_value scope_value.to_s[-2, 2].to_i end
scope_to_date(scope)
click to toggle source
# File lib/scope_methods.rb, line 37 def scope_to_date scope Date.new(year(scope), month(scope)) end
valid?(scope_value)
click to toggle source
# File lib/scope_methods.rb, line 20 def valid? scope_value scope_value = scope_value.to_s valid_month?(month(scope_value)) and valid_year?(year(scope_value)) end
valid_month?(month_in_number)
click to toggle source
# File lib/scope_methods.rb, line 41 def valid_month? month_in_number month_in_number.between? 1, 12 end
valid_year?(year_in_number)
click to toggle source
# File lib/scope_methods.rb, line 45 def valid_year? year_in_number year_in_number.between? 2000, 3000 end
year(scope_value)
click to toggle source
# File lib/scope_methods.rb, line 25 def year scope_value scope_value.to_s[0..3].to_i end