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

#==, #initialize

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from ACTV::Identity

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



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

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

.inherited(base) ⇒ Object



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

def self.inherited base
  @types << base
end

.typesObject



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

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

.valid?(response) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#attribute_pathsObject



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

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

#attributesObject



237
238
239
240
241
242
243
# File 'lib/actv/asset.rb', line 237

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)


347
348
349
350
351
# File 'lib/actv/asset.rb', line 347

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

#channelsObject Also known as: asset_channels, assetChannels



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

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

#componentsObject Also known as: asset_components, assetComponents



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

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

#descriptionObject



185
186
187
# File 'lib/actv/asset.rb', line 185

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

#description_by_type(type) ⇒ Object



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

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



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

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

#endurance_idObject



67
68
69
70
71
72
73
# File 'lib/actv/asset.rb', line 67

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)


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

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

#first_topicObject Also known as: topic



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

def first_topic
  get_first_topic_taxonomy[0]
end

#first_topic_nameObject



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

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

#first_topic_pathObject



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

def first_topic_path
  urlize first_topic
end

#has_location?Boolean

Returns:

  • (Boolean)


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

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

#has_volume_based_price?Boolean

Returns:

  • (Boolean)


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

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

#imageObject



337
338
339
# File 'lib/actv/asset.rb', line 337

def image
  image_without_placeholder
end

#image_by_name(name) ⇒ Object



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

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

#image_pathObject



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

def image_path
  default_image = 'http://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



314
315
316
317
318
319
320
# File 'lib/actv/asset.rb', line 314

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



129
130
131
132
133
# File 'lib/actv/asset.rb', line 129

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

#is_article?Boolean

Returns:

  • (Boolean)


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

def is_article?
  false
end

#is_event?Boolean

Returns:

  • (Boolean)


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

def is_event?
  false
end

#is_video?Boolean

Returns:

  • (Boolean)


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

def is_video?
  false
end

#kids?Boolean

Returns:

  • (Boolean)


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

def kids?
  kids_friendly_source_system? && kids_interest?
end

#legacy_dataObject Also known as: asset_legacy_data, assetLegacyData



115
116
117
# File 'lib/actv/asset.rb', line 115

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

#location_pathObject



265
266
267
# File 'lib/actv/asset.rb', line 265

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

#media_urlObject



333
334
335
# File 'lib/actv/asset.rb', line 333

def media_url
  image_without_placeholder.imageUrlAdr rescue ""
end

#meta_interest_pathsObject



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

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

#meta_interestsObject



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

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

#org_timezoneObject



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

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

#organizationObject



353
354
355
# File 'lib/actv/asset.rb', line 353

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

#placeObject



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

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

#place_timezoneObject



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

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

#pricesObject Also known as: asset_prices, assetPrices



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

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

#recurrencesObject



75
76
77
78
79
# File 'lib/actv/asset.rb', line 75

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

#referencesObject



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

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

#registration_statusObject Also known as: reg_status



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

def registration_status
  @registration_status ||= nil
end

#seo_url(systemName = 'as3') ⇒ Object



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

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



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

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

#sponsored?Boolean

Returns:

  • (Boolean)


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

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

#statusObject Also known as: asset_status, assetStatus



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

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

#sub_2_topicObject



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

def sub_2_topic
  get_first_topic_taxonomy[2]
end

#sub_2_topic_pathObject



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

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

#sub_3_topicObject



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

def sub_3_topic
  get_first_topic_taxonomy[3]
end

#sub_3_topic_pathObject



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

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

#sub_4_topicObject



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

def sub_4_topic
  get_first_topic_taxonomy[4]
end

#sub_4_topic_pathObject



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

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

#sub_topicObject



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

def sub_topic
  get_first_topic_taxonomy[1]
end

#sub_topic_pathObject



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

def sub_topic_path
  urlize sub_topic
end

#summaryObject



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

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

#tag_by_description(description) ⇒ Object



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

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



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

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

#topicsObject Also known as: asset_topics, assetTopics



165
166
167
168
169
# File 'lib/actv/asset.rb', line 165

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

#versionObject



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

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

#visible?Boolean

Returns:

  • (Boolean)


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

def visible?
  asset_status.visible?
end