Class: HotOrNot::CompareUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/hot-or-not/compare_url.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url, base_a, base_b, opts = {}) ⇒ CompareUrl

Returns a new instance of CompareUrl.



6
7
8
9
# File 'lib/hot-or-not/compare_url.rb', line 6

def initialize(name, url, base_a, base_b, opts={})
  @name, @url, @base_a, @base_b = name, url, base_a, base_b
  @headers = opts['headers'] || opts[:headers] || {}
end

Instance Attribute Details

#base_aObject (readonly)

Returns the value of attribute base_a.



4
5
6
# File 'lib/hot-or-not/compare_url.rb', line 4

def base_a
  @base_a
end

#base_bObject (readonly)

Returns the value of attribute base_b.



4
5
6
# File 'lib/hot-or-not/compare_url.rb', line 4

def base_b
  @base_b
end

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/hot-or-not/compare_url.rb', line 4

def headers
  @headers
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/hot-or-not/compare_url.rb', line 4

def url
  @url
end

Class Method Details

.load_from(filename) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/hot-or-not/compare_url.rb', line 27

def self.load_from(filename)
  contents = YAML.load run_erb filename
  side_a, side_b = contents['side_a'], contents['side_b']
  contents['comparisons'].map do |h|
    name = h.delete 'name'
    url = h.delete 'url'
    CompareUrl.new name, url, side_a, side_b, h
  end
end

Instance Method Details

#full_nameObject



11
12
13
# File 'lib/hot-or-not/compare_url.rb', line 11

def full_name
  @name
end

#short_nameObject



15
16
17
# File 'lib/hot-or-not/compare_url.rb', line 15

def short_name
  @short_name ||= @name.underscore.gsub(/\s+/, '_')
end

#side_aObject



19
20
21
# File 'lib/hot-or-not/compare_url.rb', line 19

def side_a
  @side_a ||= @base_a + @url
end

#side_bObject



23
24
25
# File 'lib/hot-or-not/compare_url.rb', line 23

def side_b
  @side_b ||= @base_b + @url
end