Class: MM::Command::Card

Inherits:
AbstractCommand show all
Defined in:
lib/mm/cmds/card.rb

Instance Method Summary collapse

Methods inherited from AbstractCommand

#cache_options, #card_property?, #display_value, #doc, #options, #output, #run, #user_property?

Instance Method Details

#do_onceObject



26
27
28
29
30
# File 'lib/mm/cmds/card.rb', line 26

def do_once
  output "card number => #{options[:number]}"
  output "attributes => #{options[:attrs].inspect}" if options[:attrs]
  find_card_by_number(options[:number])
end

#option_parserObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mm/cmds/card.rb', line 36

def option_parser
  OptionParser.new do |opts|
    opts.banner = "usage: mm card <card_number>"
    opts.separator ""
    opts.separator "Environment variable options:"
    opts.separator "  MM_NUMBER => card number used to find the card"
    opts.separator "  MM_ATTRS => card attributes need to show with card"
    opts.separator "  MM_SHOW_ALL => show all card attributes"
    opts.separator ""
    opts.separator "Synopsis:"
    opts.separator "mm card 1 => find card by card number 1 and show all attributes"
    opts.separator "mm card 1 -a description => find card by card number 1 and show its description"
    opts.separator ""
    opts.separator "Options:"

    opts.on("-a att_name1,attr_name2", Array, "show specified attribute value.") do |names|
      options[:attrs] = names
    end

    opts.on_tail("-s", "--show_all", "show all card attributes") do
      options[:show_all] = true
    end
  end
end

#parse(argv) ⇒ Object



32
33
34
# File 'lib/mm/cmds/card.rb', line 32

def parse(argv)
  options[:number] = argv[0].gsub(/[^\d]/, '').strip
end

#view(card) ⇒ Object



19
20
21
22
23
24
# File 'lib/mm/cmds/card.rb', line 19

def view(card)
  super(card.summarization) unless options[:show_all]
  if options[:attrs] || options[:show_all]
    super(card)
  end
end