Class: ACTV::Asset

Inherits:
Identity show all
Includes:
AssetSourceSystem
Defined in:
lib/actv/asset.rb

Constant Summary

Constants included from AssetSourceSystem

ACTV::AssetSourceSystem::SOURCE_SYSTEM_HASH

Instance Attribute Summary collapse

Attributes inherited from Base

#attrs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AssetSourceSystem

#kids_friendly_source_system?

Methods inherited from Identity

#==

Methods inherited from Base

#[], attr_reader, define_attribute_method, define_predicate_method, define_uri_method, #delete, #memoize, #method_missing, object_attr_reader, #respond_to?, #to_hash, #update, uri_attr_reader

Constructor Details

#initialize(options = {}) ⇒ Asset

Returns a new instance of Asset.



51
52
53
54
# File 'lib/actv/asset.rb', line 51

def initialize options={}
  super
  options[:logoUrlAdr]= replace_http_to_https options[:logoUrlAdr]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ACTV::Base

Instance Attribute Details

#activityEndDateObject (readonly) Also known as: end_date, activity_end_date

Returns the value of attribute activityEndDate.



23
24
25
# File 'lib/actv/asset.rb', line 23

def activityEndDate
  @activityEndDate
end

#activityEndTimeObject (readonly) Also known as: end_time

Returns the value of attribute activityEndTime.



23
24
25
# File 'lib/actv/asset.rb', line 23

def activityEndTime
  @activityEndTime
end

#activityStartDateObject (readonly) Also known as: start_date, activity_start_date

Returns the value of attribute activityStartDate.



23
24
25
# File 'lib/actv/asset.rb', line 23

def activityStartDate
  @activityStartDate
end

#activityStartTimeObject (readonly) Also known as: start_time

Returns the value of attribute activityStartTime.



23
24
25
# File 'lib/actv/asset.rb', line 23

def activityStartTime
  @activityStartTime
end

#assetDscObject (readonly)

Returns the value of attribute assetDsc.



23
24
25
# File 'lib/actv/asset.rb', line 23

def assetDsc
  @assetDsc
end

#assetGuidObject (readonly) Also known as: id

Returns the value of attribute assetGuid.



23
24
25
# File 'lib/actv/asset.rb', line 23

def assetGuid
  @assetGuid
end

#assetNameObject (readonly) Also known as: title

Returns the value of attribute assetName.



23
24
25
# File 'lib/actv/asset.rb', line 23

def assetName
  @assetName
end

#authorNameObject (readonly) Also known as: author_name

Returns the value of attribute authorName.



23
24
25
# File 'lib/actv/asset.rb', line 23

def authorName
  @authorName
end

#contactEmailAdrObject (readonly) Also known as: contact_email

Returns the value of attribute contactEmailAdr.



23
24
25
# File 'lib/actv/asset.rb', line 23

def contactEmailAdr
  @contactEmailAdr
end

#contactNameObject (readonly) Also known as: contact_name

Returns the value of attribute contactName.



23
24
25
# File 'lib/actv/asset.rb', line 23

def contactName
  @contactName
end

#contactPhoneObject (readonly) Also known as: contact_phone

Returns the value of attribute contactPhone.



23
24
25
# File 'lib/actv/asset.rb', line 23

def contactPhone
  @contactPhone
end

#contactTxtObject (readonly) Also known as: contact_txt

Returns the value of attribute contactTxt.



23
24
25
# File 'lib/actv/asset.rb', line 23

def contactTxt
  @contactTxt
end

#createdDateObject (readonly) Also known as: created_at

Returns the value of attribute createdDate.



23
24
25
# File 'lib/actv/asset.rb', line 23

def createdDate
  @createdDate
end

#currencyCdObject (readonly) Also known as: currency_code

Returns the value of attribute currencyCd.



23
24
25
# File 'lib/actv/asset.rb', line 23

def currencyCd
  @currencyCd
end

#homePageUrlAdrObject (readonly) Also known as: home_page_url

Returns the value of attribute homePageUrlAdr.



23
24
25
# File 'lib/actv/asset.rb', line 23

def homePageUrlAdr
  @homePageUrlAdr
end

#is_articleObject (readonly)

Returns the value of attribute is_article.



23
24
25
# File 'lib/actv/asset.rb', line 23

def is_article
  @is_article
end

#is_eventObject (readonly)

Returns the value of attribute is_event.



23
24
25
# File 'lib/actv/asset.rb', line 23

def is_event
  @is_event
end

#isRecurringObject (readonly) Also known as: is_recurring?

Returns the value of attribute isRecurring.



23
24
25
# File 'lib/actv/asset.rb', line 23

def isRecurring
  @isRecurring
end

#modifiedDateObject (readonly) Also known as: updated_at

Returns the value of attribute modifiedDate.



23
24
25
# File 'lib/actv/asset.rb', line 23

def modifiedDate
  @modifiedDate
end

#publishDateObject (readonly) Also known as: published_at

Returns the value of attribute publishDate.



23
24
25
# File 'lib/actv/asset.rb', line 23

def publishDate
  @publishDate
end

#regReqGenderCdObject (readonly) Also known as: required_gender

Returns the value of attribute regReqGenderCd.



23
24
25
# File 'lib/actv/asset.rb', line 23

def regReqGenderCd
  @regReqGenderCd
end

#regReqMaxAgeObject (readonly) Also known as: maximum_age

Returns the value of attribute regReqMaxAge.



23
24
25
# File 'lib/actv/asset.rb', line 23

def regReqMaxAge
  @regReqMaxAge
end

#regReqMinAgeObject (readonly) Also known as: minimum_age

Returns the value of attribute regReqMinAge.



23
24
25
# File 'lib/actv/asset.rb', line 23

def regReqMinAge
  @regReqMinAge
end

#showContactObject (readonly) Also known as: show_contact?

Returns the value of attribute showContact.



23
24
25
# File 'lib/actv/asset.rb', line 23

def showContact
  @showContact
end

Class Method Details

.from_response(response = {}) ⇒ Object



64
65
66
# File 'lib/actv/asset.rb', line 64

def self.from_response response={}
  AssetFactory.new(response[:body]).asset
end

.inherited(base) ⇒ Object



56
57
58
# File 'lib/actv/asset.rb', line 56

def self.inherited base
  @types << base
end

.typesObject



60
61
62
# File 'lib/actv/asset.rb', line 60

def self.types
  @types + Array(self)
end

.valid?(response) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/actv/asset.rb', line 68

def self.valid? response
  AssetValidator.new(response).valid?
end

Instance Method Details

#attribute_pathsObject



254
255
256
257
258
# File 'lib/actv/asset.rb', line 254

def attribute_paths
  attributes.map do |attribute|
    [sub_topic_path, urlize(attribute)].join "/"
  end
end

#attributesObject



246
247
248
249
250
251
252
# File 'lib/actv/asset.rb', line 246

def attributes
  @attributes ||= assetAttributes.sort_by do |attribute|
    attribute[:attribute][:attributeType]
  end.map do |attribute|
    attribute[:attribute][:attributeValue]
  end
end

#category_is?(name) ⇒ Boolean

Returns:

  • (Boolean)


356
357
358
359
360
# File 'lib/actv/asset.rb', line 356

def category_is? name
  @attrs[:assetCategories].any? do |cat|
    cat[:category][:categoryName].downcase == name.downcase
  end
end

#channelsObject Also known as: asset_channels, assetChannels



127
128
129
130
131
# File 'lib/actv/asset.rb', line 127

def channels
  @asset_channels ||= Array(@attrs[:assetChannels]).map do |channel|
    ACTV::AssetChannel.new(channel)
  end
end

#componentsObject Also known as: asset_components, assetComponents



153
154
155
156
157
# File 'lib/actv/asset.rb', line 153

def components
  @asset_components ||= Array(@attrs[:assetComponents]).map do |component|
    ACTV::AssetComponent.new(component)
  end
end

#descriptionObject



194
195
196
# File 'lib/actv/asset.rb', line 194

def description
  @description ||= description_by_type 'Standard'
end

#description_by_type(type) ⇒ Object



203
204
205
206
# File 'lib/actv/asset.rb', line 203

def description_by_type(type)
  dsc = self.descriptions.find { |dsc| dsc.type.name.downcase == type.downcase }
  (dsc.description.downcase == 'n/a' ? '' : dsc.description) if dsc
end

#descriptionsObject Also known as: asset_descriptions, assetDescriptions



102
103
104
105
106
107
# File 'lib/actv/asset.rb', line 102

def descriptions
  @descriptions ||= Array(@attrs[:assetDescriptions]).map do |description|
    description[:description] = convert_all_resource_to_https(description[:description])
    ACTV::AssetDescription.new(description)
  end
end

#endurance_idObject



72
73
74
75
76
77
78
# File 'lib/actv/asset.rb', line 72

def endurance_id
  if self.awendurance?
    query_values = Addressable::URI.parse(registrationUrlAdr.to_s).query_values
    query_values ||= {}
    query_values.fetch 'e', nil
  end
end

#evergreen?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'lib/actv/asset.rb', line 233

def evergreen?
  self.evergreenAssetFlag.downcase == 'true' rescue false
end

#first_topicObject Also known as: topic



278
279
280
# File 'lib/actv/asset.rb', line 278

def first_topic
  get_first_topic_taxonomy[0]
end

#first_topic_nameObject



287
288
289
# File 'lib/actv/asset.rb', line 287

def first_topic_name
  topics.first.topic.name unless topics.empty?
end

#first_topic_pathObject



283
284
285
# File 'lib/actv/asset.rb', line 283

def first_topic_path
  urlize first_topic
end

#has_location?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'lib/actv/asset.rb', line 229

def has_location?
  self.place && place.has_lat_long?
end

#has_volume_based_price?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/actv/asset.rb', line 169

def has_volume_based_price?
  prices.any? { |price| price.volume_pricing? }
end

#imageObject



346
347
348
# File 'lib/actv/asset.rb', line 346

def image
  image_without_placeholder
end

#image_by_name(name) ⇒ Object



208
209
210
# File 'lib/actv/asset.rb', line 208

def image_by_name(name)
  self.images.find { |img| img.name.downcase == name.downcase }
end

#image_pathObject



331
332
333
334
335
336
337
338
339
340
# File 'lib/actv/asset.rb', line 331

def image_path
  default_image = 'https://www.active.com/images/events/hotrace.gif'
  image = image_without_placeholder.imageUrlAdr rescue ""

  if image.empty? and (logoUrlAdr && logoUrlAdr != default_image && !(logoUrlAdr =~ URI::regexp).nil?)
    image = logoUrlAdr
  end

  image
end

#image_with_placeholderObject



323
324
325
326
327
328
329
# File 'lib/actv/asset.rb', line 323

def image_with_placeholder
  if image_path.empty?
    "/images/logo-active-icon-gray.gif"
  else
    image_path
  end
end

#imagesObject Also known as: asset_images, assetImages



135
136
137
138
139
140
141
# File 'lib/actv/asset.rb', line 135

def images
  @images ||= Array(@attrs[:assetImages]).map do |img|
    img[:imageUrlAdr] = replace_http_to_https img[:imageUrlAdr]
    img[:linkUrl] = replace_http_to_https img[:linkUrl]
    ACTV::AssetImage.new(img)
  end
end

#is_article?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'lib/actv/asset.rb', line 221

def is_article?
  false
end

#is_event?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/actv/asset.rb', line 217

def is_event?
  false
end

#is_video?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'lib/actv/asset.rb', line 225

def is_video?
  false
end

#kids?Boolean

Returns:

  • (Boolean)


237
238
239
# File 'lib/actv/asset.rb', line 237

def kids?
  kids_friendly_source_system? && kids_interest?
end

#legacy_dataObject Also known as: asset_legacy_data, assetLegacyData



121
122
123
# File 'lib/actv/asset.rb', line 121

def legacy_data
  @legacy_data ||= ACTV::AssetLegacyData.new(@attrs[:assetLegacyData]) unless @attrs[:assetLegacyData].nil?
end

#location_pathObject



274
275
276
# File 'lib/actv/asset.rb', line 274

def location_path
  @location ||= "#{place.cityName} #{place.stateProvinceCode}".downcase.gsub ' ','-'
end

#media_urlObject



342
343
344
# File 'lib/actv/asset.rb', line 342

def media_url
  image_without_placeholder.imageUrlAdr rescue ""
end

#meta_interest_pathsObject



268
269
270
271
272
# File 'lib/actv/asset.rb', line 268

def meta_interest_paths
  meta_interests.map do |meta_interest|
    [sub_topic_path, urlize(meta_interest)].join "/"
  end
end

#meta_interestsObject



260
261
262
263
264
265
266
# File 'lib/actv/asset.rb', line 260

def meta_interests
  @meta_interests ||= attrs[:assetMetaInterests].sort_by do |interest|
    interest[:sequence]
  end.map do |interest|
    interest[:metaInterest][:metaInterestName]
  end
end

#org_timezoneObject



94
95
96
# File 'lib/actv/asset.rb', line 94

def org_timezone
  @org_timezone ||= @attrs[:localTimeZoneId] unless @attrs[:localTimeZoneId].nil?
end

#organizationObject



362
363
364
# File 'lib/actv/asset.rb', line 362

def organization
  @attrs[:organization] || {}
end

#placeObject



86
87
88
# File 'lib/actv/asset.rb', line 86

def place
  @place ||= ACTV::Place.new(@attrs[:place]) unless @attrs[:place].nil?
end

#place_timezoneObject



90
91
92
# File 'lib/actv/asset.rb', line 90

def place_timezone
  @place_timezone ||= place[:timezone] unless place[:timezone].nil?
end

#pricesObject Also known as: asset_prices, assetPrices



161
162
163
164
165
# File 'lib/actv/asset.rb', line 161

def prices
  @asset_prices ||= Array(@attrs[:assetPrices]).map do |price|
    ACTV::AssetPrice.new(price)
  end
end

#recurrencesObject



80
81
82
83
84
# File 'lib/actv/asset.rb', line 80

def recurrences
  @recurrences ||= Array(@attrs[:activityRecurrences]).map do | recurrence |
    ACTV::Recurrence.new(recurrence)
  end
end

#referencesObject



350
351
352
353
354
# File 'lib/actv/asset.rb', line 350

def references
  @references ||= Array(@attrs[:assetReferences]).map do |reference|
    ACTV::AssetReference.new reference
  end
end

#registration_statusObject Also known as: reg_status



241
242
243
# File 'lib/actv/asset.rb', line 241

def registration_status
  @registration_status ||= nil
end

#seo_url(systemName = 'as3') ⇒ Object



198
199
200
201
# File 'lib/actv/asset.rb', line 198

def seo_url(systemName = 'as3')
  seo_url = self.seo_urls.find { |s| s.seoSystemName.downcase == systemName.downcase }
  seo_url.urlAdr unless seo_url.nil?
end

#seo_urlsObject Also known as: asset_seo_urls, assetSeoUrls



181
182
183
184
185
186
# File 'lib/actv/asset.rb', line 181

def seo_urls
  @seo_urls ||= Array(@attrs[:assetSeoUrls]).map do |seo_url|
    seo_url[:urlAdr] = replace_http_to_https seo_url[:urlAdr]
    ACTV::AssetSeoUrl.new(seo_url)
  end
end

#sponsored?Boolean

Returns:

  • (Boolean)


366
367
368
# File 'lib/actv/asset.rb', line 366

def sponsored?
  sponsoredContent.present? && sponsoredContent[:enabled].to_s == 'true' && sponsored_date_available?
end

#statusObject Also known as: asset_status, assetStatus



111
112
113
# File 'lib/actv/asset.rb', line 111

def status
  @status ||= ACTV::AssetStatus.new(@attrs[:assetStatus]) unless @attrs[:assetStatus].nil?
end

#sub_2_topicObject



299
300
301
# File 'lib/actv/asset.rb', line 299

def sub_2_topic
  get_first_topic_taxonomy[2]
end

#sub_2_topic_pathObject



303
304
305
# File 'lib/actv/asset.rb', line 303

def sub_2_topic_path
  urlize "#{sub_topic_path}/#{sub_2_topic}"
end

#sub_3_topicObject



307
308
309
# File 'lib/actv/asset.rb', line 307

def sub_3_topic
  get_first_topic_taxonomy[3]
end

#sub_3_topic_pathObject



311
312
313
# File 'lib/actv/asset.rb', line 311

def sub_3_topic_path
  urlize "#{sub_2_topic_path}/#{sub_3_topic}"
end

#sub_4_topicObject



315
316
317
# File 'lib/actv/asset.rb', line 315

def sub_4_topic
  get_first_topic_taxonomy[4]
end

#sub_4_topic_pathObject



319
320
321
# File 'lib/actv/asset.rb', line 319

def sub_4_topic_path
  urlize "#{sub_3_topic_path}/#{sub_4_topic}"
end

#sub_topicObject



291
292
293
# File 'lib/actv/asset.rb', line 291

def sub_topic
  get_first_topic_taxonomy[1]
end

#sub_topic_pathObject



295
296
297
# File 'lib/actv/asset.rb', line 295

def sub_topic_path
  urlize sub_topic
end

#summaryObject



190
191
192
# File 'lib/actv/asset.rb', line 190

def summary
  @summary ||= description_by_type 'summary'
end

#tag_by_description(description) ⇒ Object



212
213
214
215
# File 'lib/actv/asset.rb', line 212

def tag_by_description(description)
  asset_tag = self.tags.find { |at| at.tag.description.downcase == description.downcase }
  asset_tag.tag.name if asset_tag
end

#tagsObject Also known as: asset_tags, assetTags



145
146
147
148
149
# File 'lib/actv/asset.rb', line 145

def tags
  @asset_tags ||= Array(@attrs[:assetTags]).map do |tag|
    ACTV::AssetTag.new(tag)
  end
end

#topicsObject Also known as: asset_topics, assetTopics



173
174
175
176
177
# File 'lib/actv/asset.rb', line 173

def topics
  @asset_topics ||= Array(@attrs[:assetTopics]).map do |topic|
    ACTV::AssetTopic.new(topic)
  end.sort
end

#versionObject



98
99
100
# File 'lib/actv/asset.rb', line 98

def version
  @asset_version ||= @attrs[:assetVersion] unless @attrs[:assetVersion].nil?
end

#visible?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/actv/asset.rb', line 117

def visible?
  asset_status.visible?
end