Class: Fletcher::CLI::Utility

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/fletcher/cli/utility.rb

Instance Method Summary collapse

Instance Method Details

#fetch(url) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fletcher/cli/utility.rb', line 12

def fetch(url)
  product = Fletcher.fetch url

  # Prep output
  output_hash = Hash.new
  output_hash["name"] = product.name
  output_hash["description"] = product.description if product.description
  output_hash["price"] = product.price.format if product.price
  if product.image
    output_hash["image"] = Hash.new 
    output_hash["image"]["src"] = product.image.src 
  end 
  output_hash["url"] = product.url

  # Get single attribute
  if options[:only]
    case options[:only]
    when "image"
      value = output_hash["image"]["src"]
    else
      value = output_hash[options[:only]]
    end 
    value ? say(value.to_s) : say("Unknown attribute: #{options[:only]}")
  else 
    say output_hash.to_yaml
  end

  if options[:debug]
    say "user_agent: #{Fletcher::USER_AGENT}"
    say "response:\n\n"
    say product.doc.to_s
  end        
end

#versionObject



56
57
58
# File 'lib/fletcher/cli/utility.rb', line 56

def version
  say Fletcher.version
end

#websitesObject



47
48
49
50
51
52
# File 'lib/fletcher/cli/utility.rb', line 47

def websites
  say "Supported Websites:"
  for model in Fletcher.models.sort
    say "\t#{model.to_s.capitalize}"
  end 
end