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, options = {}) ⇒ 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, options={})
  @name, @url, @base_a, @base_b = name, url, base_a, base_b
  @options = options
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

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/hot_or_not/compare_url.rb', line 4

def options
  @options
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
36
37
38
# File 'lib/hot_or_not/compare_url.rb', line 27

def self.load_from(filename)
  contents = YAML.load(run_erb(filename)).symbolize_keys!
  side_a, side_b, comparisons = contents.delete(:side_a), contents.delete(:side_b), contents.delete(:comparisons)
  raise "Your file is not in the proper format" unless side_a && side_b && comparisons
  comparisons.map do |h|
    h.symbolize_keys!
    name = h.delete :name
    url = h.delete :url
    options = contents.merge h
    CompareUrl.new name, url, side_a, side_b, options
  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