Class: Pinch::Ticket

Inherits:
Object
  • Object
show all
Defined in:
lib/pinch/models/ticket.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#accessString (readonly)

TODO: Write general description for this method

Returns:



36
37
38
# File 'lib/pinch/models/ticket.rb', line 36

def access
  @access
end

#agencyString (readonly)

TODO: Write general description for this method

Returns:



40
41
42
# File 'lib/pinch/models/ticket.rb', line 40

def agency
  @agency
end

#buildingBuilding (readonly)

TODO: Write general description for this method

Returns:



28
29
30
# File 'lib/pinch/models/ticket.rb', line 28

def building
  @building
end

#contactsList of Person (readonly)

TODO: Write general description for this method

Returns:



20
21
22
# File 'lib/pinch/models/ticket.rb', line 20

def contacts
  @contacts
end

#descriptionString (readonly)

TODO: Write general description for this method

Returns:



16
17
18
# File 'lib/pinch/models/ticket.rb', line 16

def description
  @description
end

#idString (readonly)

TODO: Write general description for this method

Returns:



8
9
10
# File 'lib/pinch/models/ticket.rb', line 8

def id
  @id
end

#managerString (readonly)

TODO: Write general description for this method

Returns:



44
45
46
# File 'lib/pinch/models/ticket.rb', line 44

def manager
  @manager
end

#nameString (readonly)

TODO: Write general description for this method

Returns:



12
13
14
# File 'lib/pinch/models/ticket.rb', line 12

def name
  @name
end

#statusString (readonly)

TODO: Write general description for this method

Returns:



24
25
26
# File 'lib/pinch/models/ticket.rb', line 24

def status
  @status
end

#unitUnit (readonly)

TODO: Write general description for this method

Returns:



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_mapObject

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_jsonObject

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