Class: GitScribe::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/gitscribe/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Options

Returns a new instance of Options.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitscribe/options.rb', line 5

def initialize(args)
  super()

  self[:title] = "Cool Tutorial"
  self[:location] = "Vancouver, BC"
  
  @opts = OptionParser.new do |o|
    o.banner = "Usage: #{File.basename($0)} [options] reponame\ne.g. #{File.basename($0)} cool-tutorial"

    o.on('--output [FILE]', 'Output file to generate blog post to') do |output|
      self[:output] = output
    end

    o.on('--title [TITLE]', 'Blog post title to use', "Default: #{self[:title]}") do |title|
      self[:title] = title
      self[:output] = default_output unless self[:output]
    end

    o.on('--location [LOCATION]', 'Add geo location to the blog post', "Default: #{self[:location]}") do |location|
      self[:location] = location
    end

    o.on_tail('-h', '--help', 'display this help and exit') do
      self[:show_help] = true
    end
  end
  
  @opts.parse!(args)
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



3
4
5
# File 'lib/gitscribe/options.rb', line 3

def opts
  @opts
end

Instance Method Details

#default_outputObject



35
36
37
# File 'lib/gitscribe/options.rb', line 35

def default_output
  "#{Date.today.strftime("%Y-%m-%d")}-#{self[:title].gsub(/\s/, '-').downcase}.textile"
end