Class: Pinch::Ticket
- Inherits:
-
Object
- Object
- Pinch::Ticket
- Defined in:
- lib/pinch/models/ticket.rb
Instance Attribute Summary collapse
-
#access ⇒ String
readonly
TODO: Write general description for this method.
-
#agency ⇒ String
readonly
TODO: Write general description for this method.
-
#building ⇒ Building
readonly
TODO: Write general description for this method.
-
#contacts ⇒ List of Person
readonly
TODO: Write general description for this method.
-
#description ⇒ String
readonly
TODO: Write general description for this method.
-
#id ⇒ String
readonly
TODO: Write general description for this method.
-
#manager ⇒ String
readonly
TODO: Write general description for this method.
-
#name ⇒ String
readonly
TODO: Write general description for this method.
-
#status ⇒ String
readonly
TODO: Write general description for this method.
-
#unit ⇒ Unit
readonly
TODO: Write general description for this method.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
Instance Method Summary collapse
-
#initialize(id = nil, name = nil, description = nil, contacts = nil, status = nil, building = nil, unit = nil, access = nil, agency = nil, manager = nil) ⇒ Ticket
constructor
A new instance of Ticket.
-
#key_map ⇒ Object
Defines the key map for json serialization.
- #method_missing(method_name) ⇒ Object
-
#to_json ⇒ Object
Creates JSON of the curent object.
Constructor Details
#initialize(id = nil, name = nil, description = nil, contacts = nil, status = nil, building = nil, unit = nil, access = nil, agency = nil, manager = nil) ⇒ Ticket
Returns a new instance of Ticket.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pinch/models/ticket.rb', line 46 def initialize(id = nil, name = nil, description = nil, contacts = nil, status = nil, building = nil, unit = nil, access = nil, agency = nil, manager = nil) @id = id @name = name @description = description @contacts = contacts @status = status @building = building @unit = unit @access = access @agency = agency @manager = manager end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
69 70 71 |
# File 'lib/pinch/models/ticket.rb', line 69 def method_missing(method_name) puts "There is no method called '#{method_name}'." end |
Instance Attribute Details
#access ⇒ String (readonly)
TODO: Write general description for this method
36 37 38 |
# File 'lib/pinch/models/ticket.rb', line 36 def access @access end |
#agency ⇒ String (readonly)
TODO: Write general description for this method
40 41 42 |
# File 'lib/pinch/models/ticket.rb', line 40 def agency @agency end |
#building ⇒ Building (readonly)
TODO: Write general description for this method
28 29 30 |
# File 'lib/pinch/models/ticket.rb', line 28 def building @building end |
#contacts ⇒ List of Person (readonly)
TODO: Write general description for this method
20 21 22 |
# File 'lib/pinch/models/ticket.rb', line 20 def contacts @contacts end |
#description ⇒ String (readonly)
TODO: Write general description for this method
16 17 18 |
# File 'lib/pinch/models/ticket.rb', line 16 def description @description end |
#id ⇒ String (readonly)
TODO: Write general description for this method
8 9 10 |
# File 'lib/pinch/models/ticket.rb', line 8 def id @id end |
#manager ⇒ String (readonly)
TODO: Write general description for this method
44 45 46 |
# File 'lib/pinch/models/ticket.rb', line 44 def manager @manager end |
#name ⇒ String (readonly)
TODO: Write general description for this method
12 13 14 |
# File 'lib/pinch/models/ticket.rb', line 12 def name @name end |
#status ⇒ String (readonly)
TODO: Write general description for this method
24 25 26 |
# File 'lib/pinch/models/ticket.rb', line 24 def status @status end |
#unit ⇒ Unit (readonly)
TODO: Write general description for this method
32 33 34 |
# File 'lib/pinch/models/ticket.rb', line 32 def unit @unit end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pinch/models/ticket.rb', line 80 def self.from_hash(hash) if hash == nil nil else # Extract variables from the hash id = hash["id"] name = hash["name"] description = hash["description"] # Parameter is an array, so we need to iterate through it contacts = nil if hash["contacts"] != nil contacts = Array.new hash["contacts"].each{|structure| contacts << Person.from_hash(structure)} end status = hash["status"] building = Building.from_hash(hash["building"]) unit = Unit.from_hash(hash["unit"]) access = hash["access"] agency = hash["agency"] manager = hash["manager"] # Create object from extracted values Ticket.new(id, name, description, contacts, status, building, unit, access, agency, manager) end end |
Instance Method Details
#key_map ⇒ Object
Defines the key map for json serialization
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pinch/models/ticket.rb', line 115 def key_map hash = {} hash['id'] = id hash['name'] = name hash['description'] = description hash['contacts'] = contacts.map(&:key_map) hash['status'] = status hash['building'] = building.key_map hash['unit'] = unit.key_map hash['access'] = access hash['agency'] = agency hash['manager'] = manager hash end |
#to_json ⇒ Object
Creates JSON of the curent object
74 75 76 77 |
# File 'lib/pinch/models/ticket.rb', line 74 def to_json hash = key_map hash.to_json end |