Class: Metrojobb::Ad

Inherits:
Model
  • Object
show all
Defined in:
lib/metrojobb/ad.rb

Constant Summary collapse

YYYY_MM_DD_REGEX =
/\d{4}-\d{2}-\d{2}/
INVALID_DATE_FORMAT_MSG =
"must be in the following format: YYYY-MM-DD"
TYPE_ERROR_MSG =
'unknown type'

Constants inherited from Model

Model::InvalidError

Instance Method Summary collapse

Methods inherited from Model

#to_xml!

Instance Method Details

#to_xml(builder: Builder::XmlMarkup.new(indent: DEFAULT_INDENT)) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/metrojobb/ad.rb', line 58

def to_xml(builder: Builder::XmlMarkup.new(indent: DEFAULT_INDENT))
  builder.ad(orderno: order_number) do |node|
    node.externalApplication(external_application)
    node.heading { |n| n.cdata!(heading.to_s) } if heading.present?
    node.jobTitle { |n| n.cdata!(job_title.to_s) } if job_title.present?
    node.summary { |n| n.cdata!(summary.to_s) } if summary.present?
    node.description { |n| n.cdata!(description.to_s) } if description.present?
    node.employer { |n| n.cdata!(employer.to_s) } if employer.present?
    node.employerHomePage { |n| n.cdata!(employer_home_page.to_s) } if employer_home_page.present?
    node.opportunities { |n| n.cdata!(opportunities.to_s) } if opportunities.present?
    node.fromdate(from_date)
    node.todate(to_date)
    node.externalLogoUrl { |n| n.cdata!(external_logo_url.to_s) } if external_logo_url.present?
    node.applicationURL { |n| n.cdata!(application_url.to_s) } if application_url.present?
    node.videoURL { |n| n.cdata!(video_url.to_s) } if video_url.present?

    location.to_xml(builder: node) if location
    contact.to_xml(builder: node) if contact
    employment_type.to_xml(builder: node) if employment_type
    category.to_xml(builder: node) if category
    region.to_xml(builder: node) if region
  end
end

#validate_category_typeObject



103
104
105
106
107
108
# File 'lib/metrojobb/ad.rb', line 103

def validate_category_type
 return unless category
 return if category.is_a?(Category)

 errors.add(:category, TYPE_ERROR_MSG)
end

#validate_category_validObject



138
139
140
141
142
143
# File 'lib/metrojobb/ad.rb', line 138

def validate_category_valid
  return unless category.respond_to?(:valid?)
  return if category.valid?

  errors.add(:category, :invalid)
end

#validate_contact_typeObject



89
90
91
92
93
94
# File 'lib/metrojobb/ad.rb', line 89

def validate_contact_type
 return unless contact
 return if contact.is_a?(Contact)

 errors.add(:contact, TYPE_ERROR_MSG)
end

#validate_contact_validObject



124
125
126
127
128
129
# File 'lib/metrojobb/ad.rb', line 124

def validate_contact_valid
  return unless contact.respond_to?(:valid?)
  return if contact.valid?

  errors.add(:contact, :invalid)
end

#validate_employment_type_typeObject



96
97
98
99
100
101
# File 'lib/metrojobb/ad.rb', line 96

def validate_employment_type_type
 return unless employment_type
 return if employment_type.is_a?(EmploymentType)

 errors.add(:employment_type, TYPE_ERROR_MSG)
end

#validate_employment_type_validObject



131
132
133
134
135
136
# File 'lib/metrojobb/ad.rb', line 131

def validate_employment_type_valid
  return unless employment_type.respond_to?(:valid?)
  return if employment_type.valid?

  errors.add(:employment_type, :invalid)
end

#validate_location_typeObject



82
83
84
85
86
87
# File 'lib/metrojobb/ad.rb', line 82

def validate_location_type
 return unless location
 return if location.is_a?(Location)

 errors.add(:location, TYPE_ERROR_MSG)
end

#validate_location_validObject



117
118
119
120
121
122
# File 'lib/metrojobb/ad.rb', line 117

def validate_location_valid
  return unless location.respond_to?(:valid?)
  return if location.valid?

  errors.add(:location, :invalid)
end

#validate_region_typeObject



110
111
112
113
114
115
# File 'lib/metrojobb/ad.rb', line 110

def validate_region_type
 return unless region
 return if region.is_a?(Region)

 errors.add(:region, TYPE_ERROR_MSG)
end

#validate_region_validObject



145
146
147
148
149
150
# File 'lib/metrojobb/ad.rb', line 145

def validate_region_valid
  return unless region.respond_to?(:valid?)
  return if region.valid?

  errors.add(:region, :invalid)
end