Class: XmlSitemap::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/xml-sitemap/item.rb

Constant Summary collapse

DEFAULT_PRIORITY =
0.5
ISO8601_REGEX =
/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, opts = {}) ⇒ Item


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/xml-sitemap/item.rb', line 13

def initialize(target, opts={})
  @target            = target.to_s.strip
  @updated           = opts[:updated]  || Time.now
  @priority          = opts[:priority]
  @changefreq        = opts[:period]
  @validate_time     = (opts[:validate_time] != false)

  # Refer to http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636 for requirement to support images in sitemap
  @image_location    = opts[:image_location]
  @image_caption     = opts[:image_caption]
  @image_geolocation = opts[:image_geolocation]
  @image_title       = opts[:image_title]
  @image_license     = opts[:image_license]

  # Refer to http://support.google.com/webmasters/bin/answer.py?hl=en&answer=80472&topic=10079&ctx=topic#2 for requirement to support videos in sitemap
  @video_thumbnail_location     = opts[:video_thumbnail_location]
  @video_title                  = opts[:video_title]
  @video_description            = opts[:video_description]
  @video_content_location       = opts[:video_content_location]
  @video_player_location        = opts[:video_player_location]
  @video_duration               = opts[:video_duration]
  @video_expiration_date        = opts[:video_expiration_date]
  @video_rating                 = opts[:video_rating]
  @video_view_count             = opts[:video_view_count]
  @video_publication_date       = opts[:video_publication_date]
  @video_family_friendly        = opts[:video_family_friendly]
  # tag
  @video_category               = opts[:video_category]
  @video_restriction            = opts[:video_restriction]
  @video_gallery_location       = opts[:video_gallery_location]
  @video_price                  = opts[:video_price]
  @video_requires_subscription  = opts[:video_requires_subscription]
  @video_uploader               = opts[:video_uploader]
  @video_platform               = opts[:video_platform]
  @video_live                   = opts[:video_live]

  if @changefreq
    @changefreq = @changefreq.to_sym
    unless XmlSitemap::PERIODS.include?(@changefreq)
      raise ArgumentError, "Invalid :period value '#{@changefreq}'"
    end
  end

  unless @updated.kind_of?(Time) || @updated.kind_of?(Date) || @updated.kind_of?(String)
    raise ArgumentError, "Time, Date, or ISO8601 String required for :updated!"
  end

  if @validate_time && @updated.kind_of?(String) && !(@updated =~ ISO8601_REGEX)
    raise ArgumentError, "String provided to :updated did not match ISO8601 standard!"
  end

  @updated = @updated.to_time if @updated.kind_of?(Date)

  ##############################################################################################
  ##############################################################################################

  unless @video_expiration_date.kind_of?(Time) || @video_expiration_date.kind_of?(Date) || @video_expiration_date.kind_of?(String)
    raise ArgumentError, "Time, Date, or ISO8601 String required for :video_expiration_date!" unless @video_expiration_date.nil?
  end

  if @validate_time && @video_expiration_date.kind_of?(String) && !(@video_expiration_date =~ ISO8601_REGEX)
    raise ArgumentError, "String provided to :video_expiration_date did not match ISO8601 standard!"
  end

  @video_expiration_date = @video_expiration_date.to_time if @video_expiration_date.kind_of?(Date)

  ##############################################################################################
  ##############################################################################################

  unless @video_publication_date.kind_of?(Time) || @video_publication_date.kind_of?(Date) || @video_publication_date.kind_of?(String)
    raise ArgumentError, "Time, Date, or ISO8601 String required for :video_publication_date!" unless @video_publication_date.nil?
  end

  if @validate_time && @video_publication_date.kind_of?(String) && !(@video_publication_date =~ ISO8601_REGEX)
    raise ArgumentError, "String provided to :video_publication_date did not match ISO8601 standard!"
  end

  @video_publication_date = @video_publication_date.to_time if @video_publication_date.kind_of?(Date)
end

Instance Attribute Details

#changefreqObject (readonly)

Returns the value of attribute changefreq


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def changefreq
  @changefreq
end

#image_captionObject (readonly)

Returns the value of attribute image_caption


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def image_caption
  @image_caption
end

#image_geolocationObject (readonly)

Returns the value of attribute image_geolocation


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def image_geolocation
  @image_geolocation
end

#image_licenseObject (readonly)

Returns the value of attribute image_license


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def image_license
  @image_license
end

#image_locationObject (readonly)

Returns the value of attribute image_location


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def image_location
  @image_location
end

#image_titleObject (readonly)

Returns the value of attribute image_title


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def image_title
  @image_title
end

#priorityObject (readonly)

Returns the value of attribute priority


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def priority
  @priority
end

#targetObject (readonly)

Returns the value of attribute target


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def target
  @target
end

#updatedObject (readonly)

Returns the value of attribute updated


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def updated
  @updated
end

#validate_timeObject (readonly)

Returns the value of attribute validate_time


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def validate_time
  @validate_time
end

#video_categoryObject (readonly)

Returns the value of attribute video_category


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_category
  @video_category
end

#video_content_locationObject (readonly)

Returns the value of attribute video_content_location


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_content_location
  @video_content_location
end

#video_descriptionObject (readonly)

Returns the value of attribute video_description


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_description
  @video_description
end

#video_durationObject (readonly)

Returns the value of attribute video_duration


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_duration
  @video_duration
end

#video_expiration_dateObject (readonly)

Returns the value of attribute video_expiration_date


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_expiration_date
  @video_expiration_date
end

#video_family_friendlyObject (readonly)

Returns the value of attribute video_family_friendly


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_family_friendly
  @video_family_friendly
end

Returns the value of attribute video_gallery_location


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_gallery_location
  @video_gallery_location
end

#video_liveObject (readonly)

Returns the value of attribute video_live


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_live
  @video_live
end

#video_platformObject (readonly)

Returns the value of attribute video_platform


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_platform
  @video_platform
end

#video_player_locationObject (readonly)

Returns the value of attribute video_player_location


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_player_location
  @video_player_location
end

#video_priceObject (readonly)

Returns the value of attribute video_price


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_price
  @video_price
end

#video_publication_dateObject (readonly)

Returns the value of attribute video_publication_date


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_publication_date
  @video_publication_date
end

#video_ratingObject (readonly)

Returns the value of attribute video_rating


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_rating
  @video_rating
end

#video_requires_subscriptionObject (readonly)

Returns the value of attribute video_requires_subscription


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_requires_subscription
  @video_requires_subscription
end

#video_restrictionObject (readonly)

Returns the value of attribute video_restriction


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_restriction
  @video_restriction
end

#video_thumbnail_locationObject (readonly)

Returns the value of attribute video_thumbnail_location


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_thumbnail_location
  @video_thumbnail_location
end

#video_titleObject (readonly)

Returns the value of attribute video_title


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_title
  @video_title
end

#video_uploaderObject (readonly)

Returns the value of attribute video_uploader


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_uploader
  @video_uploader
end

#video_view_countObject (readonly)

Returns the value of attribute video_view_count


8
9
10
# File 'lib/xml-sitemap/item.rb', line 8

def video_view_count
  @video_view_count
end

Instance Method Details

#lastmod_valueObject

Returns the timestamp value of lastmod for renderer


95
96
97
98
99
100
101
# File 'lib/xml-sitemap/item.rb', line 95

def lastmod_value
  if @updated.kind_of?(Time)
    @updated.utc.iso8601
  else
    @updated.to_s
  end
end

#video_expiration_date_valueObject

Returns the timestamp value of video:expiration_date for renderer


105
106
107
108
109
110
111
# File 'lib/xml-sitemap/item.rb', line 105

def video_expiration_date_value
  if @video_expiration_date.kind_of?(Time)
    @video_expiration_date.utc.iso8601
  else
    @video_expiration_date.to_s
  end
end

#video_publication_date_valueObject

Returns the timestamp value of video:publication_date for renderer


115
116
117
118
119
120
121
# File 'lib/xml-sitemap/item.rb', line 115

def video_publication_date_value
  if @video_publication_date.kind_of?(Time)
    @video_publication_date.utc.iso8601
  else
    @video_publication_date.to_s
  end
end