Class: Simulacrum::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/simulacrum/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Component

Returns a new instance of Component.



11
12
13
14
15
# File 'lib/simulacrum/component.rb', line 11

def initialize(name, options = {})
  @name = name
  @options = options
  @renderer = Simulacrum::Renderer.new(options.url)
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



8
9
10
# File 'lib/simulacrum/component.rb', line 8

def browser
  @browser
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/simulacrum/component.rb', line 8

def name
  @name
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/simulacrum/component.rb', line 9

def options
  @options
end

Instance Method Details

#acceptable_deltaObject



38
39
40
# File 'lib/simulacrum/component.rb', line 38

def acceptable_delta
  options.acceptable_delta || Simulacrum.configuration.acceptable_delta
end

#candidate?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/simulacrum/component.rb', line 30

def candidate?
  File.exists?(candidate_path)
end

#candidate_pathObject



47
48
49
50
# File 'lib/simulacrum/component.rb', line 47

def candidate_path
  filename = Simulacrum.configuration.candidate_filename
  File.join(root_path, "#{filename}.png")
end

#diff?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/simulacrum/component.rb', line 34

def diff?
  File.exists?(diff_path)
end

#diff_pathObject



52
53
54
55
# File 'lib/simulacrum/component.rb', line 52

def diff_path
  filename = Simulacrum.configuration.diff_filename
  File.join(root_path, "#{filename}.png")
end

#reference?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/simulacrum/component.rb', line 26

def reference?
  File.exists?(reference_path)
end

#reference_pathObject



42
43
44
45
# File 'lib/simulacrum/component.rb', line 42

def reference_path
  filename = Simulacrum.configuration.reference_filename
  File.join(root_path, "#{filename}.png")
end

#remove_candidateObject



57
58
59
# File 'lib/simulacrum/component.rb', line 57

def remove_candidate
  FileUtils.rm(candidate_path) if candidate?
end

#remove_diffObject



61
62
63
# File 'lib/simulacrum/component.rb', line 61

def remove_diff
  FileUtils.rm(diff_path) if diff?
end

#renderObject

Load up the component url and capture an image, returns a File object



18
19
20
21
22
23
24
# File 'lib/simulacrum/component.rb', line 18

def render
  ensure_example_path
  save_candidate(@renderer.render)
  crop_candidate_to_selector
ensure
  cleanup
end