Class: SyoboiCalendar::Queries::Base
- Inherits:
-
Object
- Object
- SyoboiCalendar::Queries::Base
- Defined in:
- lib/syoboi_calendar/queries/base.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #last_update ⇒ Object
- #properties ⇒ Object
- #to_hash ⇒ Object
- #to_hash_with_nil_value ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
54 55 56 |
# File 'lib/syoboi_calendar/queries/base.rb', line 54 def initialize( = {}) = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
52 53 54 |
# File 'lib/syoboi_calendar/queries/base.rb', line 52 def end |
Class Method Details
.option(*options) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/syoboi_calendar/queries/base.rb', line 9 def option(*) .each do |option| define_method(option) do self.[option] end end end |
.property(*properties) ⇒ Object
5 6 7 |
# File 'lib/syoboi_calendar/queries/base.rb', line 5 def property(*properties) self.properties += properties end |
.time_option(*names) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/syoboi_calendar/queries/base.rb', line 17 def time_option(*names) names.each do |name| define_method("has_#{name}_time?") do !!(send("#{name}_from") || send("#{name}_to")) end define_method("formatted_#{name}_from") do send("#{name}_from").try(:strftime, "%Y%m%d_%H%M%S") end define_method("formatted_#{name}_to") do send("#{name}_to").try(:strftime, "%Y%m%d_%H%M%S") end end end |
Instance Method Details
#last_update ⇒ Object
72 73 74 |
# File 'lib/syoboi_calendar/queries/base.rb', line 72 def last_update "#{formatted_updated_from}-#{formatted_updated_to}" if has_updated_time? end |
#properties ⇒ Object
68 69 70 |
# File 'lib/syoboi_calendar/queries/base.rb', line 68 def properties self.class.properties end |
#to_hash ⇒ Object
58 59 60 |
# File 'lib/syoboi_calendar/queries/base.rb', line 58 def to_hash to_hash_with_nil_value.reject {|key, value| value.nil? } end |
#to_hash_with_nil_value ⇒ Object
62 63 64 65 66 |
# File 'lib/syoboi_calendar/queries/base.rb', line 62 def to_hash_with_nil_value properties.inject({}) do |hash, property| hash.merge(property => send(property.to_s.underscore)) end end |