Class: SearchCopGrammar::Attributes::Date
- Inherits:
-
Datetime
- Object
- Base
- WithoutMatches
- Datetime
- SearchCopGrammar::Attributes::Date
- Defined in:
- lib/search_cop_grammar/attributes.rb
Instance Attribute Summary
Attributes inherited from Base
#attribute, #column_name, #options, #table_alias
Instance Method Summary collapse
Methods inherited from Datetime
#between, #eq, #gt, #map, #not_eq
Methods inherited from WithoutMatches
Methods inherited from Base
#compatible?, #fulltext?, #initialize, #map, #method_missing, #respond_to?
Constructor Details
This class inherits a constructor from SearchCopGrammar::Attributes::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SearchCopGrammar::Attributes::Base
Instance Method Details
#parse(value) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/search_cop_grammar/attributes.rb', line 224 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 elsif value =~ /[0-9]{4}(\.|-|\/)[0-9]{1,2}(\.|-|\/)[0-9]{1,2}/ || value =~ /[0-9]{1,2}(\.|-|\/)[0-9]{1,2}(\.|-|\/)[0-9]{4}/ date = ::Date.parse(value) date .. date else raise ArgumentError end rescue ArgumentError raise SearchCop::IncompatibleDatatype, "Incompatible datatype for #{value}" end |