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



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

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

#attributesObject



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

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)


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

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



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

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

#descriptionObject



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

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

#description_by_type(type) ⇒ Object



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

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)


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

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

#first_topicObject Also known as: topic



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

def first_topic
  get_first_topic_taxonomy[0]
end

#first_topic_nameObject



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

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

#first_topic_pathObject



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

def first_topic_path
  urlize first_topic
end

#has_location?Boolean

Returns:

  • (Boolean)


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

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

#has_volume_based_price?Boolean

Returns:

  • (Boolean)


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

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

#imageObject



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

def image
  image_without_placeholder
end

#image_by_name(name) ⇒ Object



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

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

#image_pathObject



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

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



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

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
# File 'lib/actv/asset.rb', line 135

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

#is_article?Boolean

Returns:

  • (Boolean)


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

def is_article?
  false
end

#is_event?Boolean

Returns:

  • (Boolean)


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

def is_event?
  false
end

#is_video?Boolean

Returns:

  • (Boolean)


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

def is_video?
  false
end

#kids?Boolean

Returns:

  • (Boolean)


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

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



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

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

#media_urlObject



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

def media_url
  image_without_placeholder.imageUrlAdr rescue ""
end

#meta_interest_pathsObject



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

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

#meta_interestsObject



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

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



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

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



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

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



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

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

#registration_statusObject Also known as: reg_status



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

def registration_status
  @registration_status ||= nil
end

#seo_url(systemName = 'as3') ⇒ Object



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

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



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

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)


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

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



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

def sub_2_topic
  get_first_topic_taxonomy[2]
end

#sub_2_topic_pathObject



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

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

#sub_3_topicObject



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

def sub_3_topic
  get_first_topic_taxonomy[3]
end

#sub_3_topic_pathObject



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

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

#sub_4_topicObject



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

def sub_4_topic
  get_first_topic_taxonomy[4]
end

#sub_4_topic_pathObject



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

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

#sub_topicObject



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

def sub_topic
  get_first_topic_taxonomy[1]
end

#sub_topic_pathObject



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

def sub_topic_path
  urlize sub_topic
end

#summaryObject



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

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

#tag_by_description(description) ⇒ Object



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

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



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

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

#topicsObject Also known as: asset_topics, assetTopics



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

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