Class: TicketEvolution::Builder
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- TicketEvolution::Builder
- Includes:
- SingularClass
- Defined in:
- lib/ticket_evolution/core/builder.rb
Instance Method Summary collapse
- #id ⇒ Object
-
#id=(id) ⇒ Object
Ruby 1.8.7 / REE compatibility.
-
#initialize(hash = {}) ⇒ Builder
constructor
A new instance of Builder.
- #to_hash ⇒ Object
Methods included from SingularClass
Constructor Details
#initialize(hash = {}) ⇒ Builder
Returns a new instance of Builder.
5 6 7 8 9 10 11 12 |
# File 'lib/ticket_evolution/core/builder.rb', line 5 def initialize(hash={}) attrs = hash.clone @table = attrs['id'].present? ? {:id => attrs.delete('id')} : {} attrs.each do |k, v| @table[k.to_sym] = process_datum(v, k) new_ostruct_member(k) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object (private)
56 57 58 59 60 61 62 63 64 |
# File 'lib/ticket_evolution/core/builder.rb', line 56 def method_missing(meth, *args) if args.size == 1 super(meth, process_datum(args.first, meth)) elsif args.size == 0 super(meth) else super(meth, process_datum(args, meth)) end end |
Instance Method Details
#id ⇒ Object
27 28 29 |
# File 'lib/ticket_evolution/core/builder.rb', line 27 def id @table[:id] end |
#id=(id) ⇒ Object
Ruby 1.8.7 / REE compatibility
23 24 25 |
# File 'lib/ticket_evolution/core/builder.rb', line 23 def id=(id) @table[:id] = id end |
#to_hash ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ticket_evolution/core/builder.rb', line 14 def to_hash hash = {} @table.each do |k, v| hash[k] = from_ostruct(v) end hash end |