Class: Gyunyu::Command::Export::Option
- Inherits:
-
Object
- Object
- Gyunyu::Command::Export::Option
- Defined in:
- lib/gyunyu/command/export/option.rb
Defined Under Namespace
Classes: CustomFilterNotFound, FormatNotFound
Constant Summary collapse
- FIELD_SEP =
','
Instance Attribute Summary collapse
-
#custom_filter ⇒ Object
readonly
Returns the value of attribute custom_filter.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#lists ⇒ Object
readonly
Returns the value of attribute lists.
-
#show_filter_list ⇒ Object
readonly
Returns the value of attribute show_filter_list.
Instance Method Summary collapse
-
#initialize(argv = []) ⇒ Option
constructor
A new instance of Option.
- #parser ⇒ Object
Constructor Details
#initialize(argv = []) ⇒ Option
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gyunyu/command/export/option.rb', line 13 def initialize( argv = [] ) @lists = [] @filter = nil @custom_filter = nil @fields = [] @format = :csv @show_filter_list = false parser.parse( argv ) end |
Instance Attribute Details
#custom_filter ⇒ Object (readonly)
Returns the value of attribute custom_filter.
23 24 25 |
# File 'lib/gyunyu/command/export/option.rb', line 23 def custom_filter @custom_filter end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
23 24 25 |
# File 'lib/gyunyu/command/export/option.rb', line 23 def fields @fields end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
23 24 25 |
# File 'lib/gyunyu/command/export/option.rb', line 23 def filter @filter end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
23 24 25 |
# File 'lib/gyunyu/command/export/option.rb', line 23 def format @format end |
#lists ⇒ Object (readonly)
Returns the value of attribute lists.
23 24 25 |
# File 'lib/gyunyu/command/export/option.rb', line 23 def lists @lists end |
#show_filter_list ⇒ Object (readonly)
Returns the value of attribute show_filter_list.
23 24 25 |
# File 'lib/gyunyu/command/export/option.rb', line 23 def show_filter_list @show_filter_list end |
Instance Method Details
#parser ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gyunyu/command/export/option.rb', line 33 def parser OptionParser.new do |opt| opt.on('-l', '--list LIST') { |list| if !@lists.include?( list ) @lists << list end } opt.on('-f', '--filter FILTER') { |filter| @filter = filter if filter.size > 0 } opt.on('-c', '--custom-filter FILTER') { |filter| mod = Module.nesting[1].const_get('CustomFilter') if mod.filter.has_key?( filter ) @custom_filter = filter else raise CustomFilterNotFound end } opt.on('-s', '--custom-filter-list') { |c| @show_filter_list = true } opt.on('-d', '--field FIELD') { |field| if field.include?( FIELD_SEP ) @fields = field.split( FIELD_SEP ) elsif !@fields.include?( field ) @fields << field end } opt.on('-o', '--format FORMAT') { |format| format.downcase! formats = Format.constants.map { |e| e.to_s.downcase } if formats.include?( format ) @format = format else raise FormatNotFound end } end end |