Class: Popart::Config
- Inherits:
-
Object
- Object
- Popart::Config
- Defined in:
- lib/popart/config.rb
Instance Attribute Summary collapse
-
#browsers ⇒ Object
Returns the value of attribute browsers.
-
#output_directory ⇒ Object
Returns the value of attribute output_directory.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #default_browsers ⇒ Object
- #default_output_directory ⇒ Object
- #initial_config ⇒ Object
- #load_from_file(filename) ⇒ Object
- #set_defaults ⇒ Object
- #set_site(site) ⇒ Object
- #verify_output_directory ⇒ Object
Instance Attribute Details
#browsers ⇒ Object
Returns the value of attribute browsers.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def browsers @browsers end |
#output_directory ⇒ Object
Returns the value of attribute output_directory.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def output_directory @output_directory end |
#site ⇒ Object
Returns the value of attribute site.
7 8 9 |
# File 'lib/popart/config.rb', line 7 def site @site end |
Instance Method Details
#default_browsers ⇒ Object
9 10 11 12 13 14 |
# File 'lib/popart/config.rb', line 9 def default_browsers [ {"browserName" => 'Chrome', "platform" => "Windows 10", "version" => "latest"}, {"browserName" => 'Firefox', "platform" => "Windows 10", "version" => "latest"} ] end |
#default_output_directory ⇒ Object
16 17 18 |
# File 'lib/popart/config.rb', line 16 def default_output_directory './screenshots' end |
#initial_config ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/popart/config.rb', line 20 def initial_config fn = ARGV[1] ||= './config.json' path = Pathname.new fn load_from_file path if path.exist? set_defaults end |
#load_from_file(filename) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/popart/config.rb', line 29 def load_from_file filename filedata = File.read filename config_hash = YAML.load(filedata) @browsers = [config_hash["browsers"]].flatten @output_directory = config_hash["output_directory"] @site = config_hash["site"] end |
#set_defaults ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/popart/config.rb', line 38 def set_defaults @browsers ||= default_browsers @output_directory ||= default_output_directory set_site(@site ||= ARGV[0]) @output_directory = Pathname.new @output_directory verify_output_directory end |
#set_site(site) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/popart/config.rb', line 48 def set_site site unless site STDERR.puts "You must provide a site to screenshot." exit end @site = URI site end |
#verify_output_directory ⇒ Object
58 59 60 61 62 63 |
# File 'lib/popart/config.rb', line 58 def verify_output_directory unless @output_directory.exist? STDERR.puts "#{@output_directory} doesn't seem to exist; creating it." Dir.mkdir @output_directory end end |