class Ppl::Command::Name
Attributes
list_format[W]
name_service[W]
show_format[W]
Public Instance Methods
execute(input, output)
click to toggle source
# File lib/ppl/command/name.rb, line 29 def execute(input, output) action = determine_action(input) send(action, input, output) end
options(parser, options)
click to toggle source
# File lib/ppl/command/name.rb, line 10 def options(parser, options) parser.banner = "usage: ppl name <contact> [<name>]" parser.on("-f", "--family <family-name(s)>") do |family| options[:family] = family end parser.on("-g", "--given <given-name(s)>") do |given| options[:given] = given end parser.on("-m", "--middle <middle-name(s)>") do |middle| options[:middle] = middle end parser.on("-p", "--prefix <prefix>") do |prefix| options[:prefix] = prefix end parser.on("-s", "--suffix <suffix>") do |suffix| options[:suffix] = suffix end end
Private Instance Methods
determine_action(input)
click to toggle source
# File lib/ppl/command/name.rb, line 36 def determine_action(input) if input.arguments[0].nil? :list_names elsif input.arguments[1].nil? && input.options.empty? :show_name else :set_name end end
list_names(input, output)
click to toggle source
# File lib/ppl/command/name.rb, line 46 def list_names(input, output) address_book = @storage.load_address_book name_list = @list_format.process(address_book) output.line(name_list) end
set_name(input, output)
click to toggle source
# File lib/ppl/command/name.rb, line 63 def set_name(input, output) contact = @storage.require_contact(input.arguments[0]) options = input.options.dup if !input.arguments[1].nil? options[:full] = input.arguments[1].dup end @name_service.update(contact.name, options) @storage.save_contact(contact) end
show_name(input, output)
click to toggle source
# File lib/ppl/command/name.rb, line 52 def show_name(input, output) contact = @storage.require_contact(input.arguments[0]) name = @show_format.process(contact.name) if name != "" output.line(name) true else false end end