Class: REIformslive::UserTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/reiformslive/user_template.rb

Constant Summary collapse

PATH =
'/user-templates'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: '{}') ⇒ UserTemplate

Returns a new instance of UserTemplate.



7
8
9
# File 'lib/reiformslive/user_template.rb', line 7

def initialize data: '{}'
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/reiformslive/user_template.rb', line 5

def data
  @data
end

Class Method Details

.allObject



79
80
81
82
83
84
# File 'lib/reiformslive/user_template.rb', line 79

def self.all
  REIformslive::Session
    .get(path: PATH)
    .parse_json
    .map{|data| self.new data: data }
end

.find(id) ⇒ Object



86
87
88
89
90
91
# File 'lib/reiformslive/user_template.rb', line 86

def self.find id
  self.new data:
    REIformslive::Session
      .get(path: "#{PATH}/#{id}")
      .parse_json
end

Instance Method Details

#agency_idObject



19
20
21
# File 'lib/reiformslive/user_template.rb', line 19

def agency_id
  data['agency_id'].to_i
end

#created_atObject



43
44
45
# File 'lib/reiformslive/user_template.rb', line 43

def created_at
  Time.at data['created'].to_i
end

#finalised?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/reiformslive/user_template.rb', line 35

def finalised?
  data['finalised'].to_s == 'true'
end

#full_nameObject



59
60
61
# File 'lib/reiformslive/user_template.rb', line 59

def full_name
  "#{given_name} #{surname}"
end

#given_nameObject



51
52
53
# File 'lib/reiformslive/user_template.rb', line 51

def given_name
  data['given_name']
end

#idObject



11
12
13
# File 'lib/reiformslive/user_template.rb', line 11

def id
  data['id'].to_i
end

#nameObject



27
28
29
# File 'lib/reiformslive/user_template.rb', line 27

def name
  data['name']
end

#original_template_codeObject



75
76
77
# File 'lib/reiformslive/user_template.rb', line 75

def original_template_code
  data['template_code']
end

#original_template_nameObject



71
72
73
# File 'lib/reiformslive/user_template.rb', line 71

def original_template_name
  data['template_name']
end

#private?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/reiformslive/user_template.rb', line 39

def private?
  data['private'].to_s == 'true'
end

#surnameObject



55
56
57
# File 'lib/reiformslive/user_template.rb', line 55

def surname
  data['surname']
end

#template?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/reiformslive/user_template.rb', line 31

def template?
  data['template'].to_s == 'true'
end

#template_costObject



63
64
65
# File 'lib/reiformslive/user_template.rb', line 63

def template_cost
  data['template_cost'].to_i
end

#template_idObject



67
68
69
# File 'lib/reiformslive/user_template.rb', line 67

def template_id
  data['template_id'].to_i
end

#template_version_idObject



15
16
17
# File 'lib/reiformslive/user_template.rb', line 15

def template_version_id
  data['template_version_id'].to_i
end

#updated_atObject



47
48
49
# File 'lib/reiformslive/user_template.rb', line 47

def updated_at
  Time.at data['updated'].to_i
end

#user_idObject



23
24
25
# File 'lib/reiformslive/user_template.rb', line 23

def user_id
  data['user_id'].to_i
end