class AttrSearchableGrammar::Attributes::Date
Public Instance Methods
parse(value)
click to toggle source
# File lib/attr_searchable_grammar/attributes.rb, line 197 def parse(value) return value .. value unless value.is_a?(::String) if value =~ /^[0-9]{4,}$/ ::Date.new(value.to_i).beginning_of_year .. ::Date.new(value.to_i).end_of_year elsif value =~ /^([0-9]{4,})(\.|-|\/)([0-9]{1,2})$/ ::Date.new($1.to_i, $3.to_i, 15).beginning_of_month .. ::Date.new($1.to_i, $3.to_i, 15).end_of_month elsif value =~ /^([0-9]{1,2})(\.|-|\/)([0-9]{4,})$/ ::Date.new($3.to_i, $1.to_i, 15).beginning_of_month .. ::Date.new($3.to_i, $1.to_i, 15).end_of_month else date = ::Date.parse(value) date .. date end rescue ArgumentError raise AttrSearchable::IncompatibleDatatype, "Incompatible datatype for #{value}" end