Class: Kuler::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/kuler/theme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Theme

create a new Kuler::Theme from a Nokogiri::XML::Element



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kuler/theme.rb', line 28

def initialize( input )
  @theme_id    = input.at( "//kuler:themeID"     ).text.to_i
  @title       = input.at( "//kuler:themeTitle"  ).text
  @tags        = input.at( "//kuler:themeTags"   ).text.gsub(/\s/, '').split(',')
  @rating      = input.at( "//kuler:themeRating" ).text.to_i

  @author_name = input.at( "//kuler:themeAuthor/kuler:authorLabel" ).text
  @author_id   = input.at( "//kuler:themeAuthor/kuler:authorID"    ).text.to_i

  @swatches = input.search( "//kuler:swatch" ).map {|nodes| Kuler::Swatch.new nodes }
end

Instance Attribute Details

#author_idObject (readonly)

the Kuler ID for the theme’s creator



20
21
22
# File 'lib/kuler/theme.rb', line 20

def author_id
  @author_id
end

#author_nameObject (readonly)

the display name of the theme’s creator



17
18
19
# File 'lib/kuler/theme.rb', line 17

def author_name
  @author_name
end

#ratingObject (readonly)

theme rating, 1-5



14
15
16
# File 'lib/kuler/theme.rb', line 14

def rating
  @rating
end

#swatchesObject (readonly)

an array of Kuler::Swatch objects representing the colors in this theme



24
25
26
# File 'lib/kuler/theme.rb', line 24

def swatches
  @swatches
end

#tagsObject (readonly)

array of tags attached to this theme



11
12
13
# File 'lib/kuler/theme.rb', line 11

def tags
  @tags
end

#theme_idObject (readonly)

the Kuler ID for the theme



5
6
7
# File 'lib/kuler/theme.rb', line 5

def theme_id
  @theme_id
end

#titleObject (readonly)

the title of the theme



8
9
10
# File 'lib/kuler/theme.rb', line 8

def title
  @title
end

Instance Method Details

#hex_codesObject

returns an array of hex values of the swatches in this theme



42
43
44
# File 'lib/kuler/theme.rb', line 42

def hex_codes
  self.swatches.map {|s| s.hex_code }
end