Class: SyoboiCalendar::QueryBuilders::Base
- Inherits:
-
Object
- Object
- SyoboiCalendar::QueryBuilders::Base
- Defined in:
- lib/syoboi_calendar/query_builders/base.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .build(*args) ⇒ Object
- .option(*options) ⇒ Object
- .property(*properties) ⇒ Object
- .time_option(*names) ⇒ Object
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
Returns a new instance of Base.
58 59 60 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 58 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
56 57 58 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 56 def @options end |
Class Method Details
.build(*args) ⇒ Object
5 6 7 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 5 def build(*args) new(*args).to_hash end |
.option(*options) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 13 def option(*) .each do |option| define_method(option) do self.[option] end end end |
.property(*properties) ⇒ Object
9 10 11 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 9 def property(*properties) self.properties += properties end |
.time_option(*names) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 21 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
76 77 78 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 76 def last_update "#{formatted_updated_from}-#{formatted_updated_to}" if has_updated_time? end |
#properties ⇒ Object
72 73 74 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 72 def properties self.class.properties end |
#to_hash ⇒ Object
62 63 64 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 62 def to_hash to_hash_with_nil_value.reject {|key, value| value.nil? } end |
#to_hash_with_nil_value ⇒ Object
66 67 68 69 70 |
# File 'lib/syoboi_calendar/query_builders/base.rb', line 66 def to_hash_with_nil_value properties.inject({}) do |hash, property| hash.merge(property => send(property.to_s.underscore)) end end |