Class: Kaimono::Options
- Inherits:
-
Object
- Object
- Kaimono::Options
- Defined in:
- lib/kaimono/options.rb
Instance Method Summary collapse
- #filename ⇒ Object
- #get_tasklist ⇒ Object
- #hash_key_to_sym(h) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #load_config(file) ⇒ Object
- #parse(argv) ⇒ Object
- #to_html ⇒ Object
- #to_s ⇒ Object
- #usage_message ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
3 4 5 6 |
# File 'lib/kaimono/options.rb', line 3 def initialize @options = {} @config = {} end |
Instance Method Details
#filename ⇒ Object
21 22 23 |
# File 'lib/kaimono/options.rb', line 21 def filename @options[:filename].to_s end |
#get_tasklist ⇒ Object
12 13 14 |
# File 'lib/kaimono/options.rb', line 12 def get_tasklist @options[:task] = hash_key_to_sym(@config) end |
#hash_key_to_sym(h) ⇒ Object
8 9 10 |
# File 'lib/kaimono/options.rb', line 8 def hash_key_to_sym(h) Hash[h.map{|k, v| [k.to_s.to_sym, v]}] end |
#load_config(file) ⇒ Object
16 17 18 19 |
# File 'lib/kaimono/options.rb', line 16 def load_config(file) @config = YAML.load(File.read(file)) get_tasklist end |
#parse(argv) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kaimono/options.rb', line 54 def parse(argv) if argv.empty? || (argv.size > 1) || File.extname(argv.first) != ".yml" exit end if File.exist?(argv.first) yaml_file = argv.first @options[:filename] = File.basename(yaml_file, ".yml") load_config(yaml_file) else puts "file not exist => #{argv.first}" exit end @options end |
#to_html ⇒ Object
40 41 42 43 44 |
# File 'lib/kaimono/options.rb', line 40 def to_html haml = Haml::Template.new {Kaimono::HTML_TEMPLATE} html = haml.render(Object.new, {task: @options[:task]}) html end |
#to_s ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kaimono/options.rb', line 25 def to_s str = [] str << "---------- file name ----------" str << @options[:filename].to_s @options[:task].each do |k,v| str << "------------------------------" str << "task name: #{k.to_s}" str << "------------------------------" str << "item:" v.each {|item| str << item.to_s} end str end |