Class: Hiiro::Args
- Inherits:
-
Object
- Object
- Hiiro::Args
- Defined in:
- lib/hiiro.rb
Instance Attribute Summary collapse
-
#raw_args ⇒ Object
readonly
Returns the value of attribute raw_args.
Instance Method Summary collapse
- #flag?(flag) ⇒ Boolean
- #flag_value(flag) ⇒ Object
- #flags ⇒ Object
-
#initialize(*raw_args) ⇒ Args
constructor
A new instance of Args.
- #values ⇒ Object
Constructor Details
#initialize(*raw_args) ⇒ Args
Returns a new instance of Args.
778 779 780 |
# File 'lib/hiiro.rb', line 778 def initialize(*raw_args) @raw_args = raw_args end |
Instance Attribute Details
#raw_args ⇒ Object (readonly)
Returns the value of attribute raw_args.
776 777 778 |
# File 'lib/hiiro.rb', line 776 def raw_args @raw_args end |
Instance Method Details
#flag?(flag) ⇒ Boolean
792 793 794 |
# File 'lib/hiiro.rb', line 792 def flag?(flag) flags.include?(flag) end |
#flag_value(flag) ⇒ Object
796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/hiiro.rb', line 796 def flag_value(flag) found_flag = false raw_args.each do |arg| if found_flag return arg end if arg.match?(/^-\w*#{flag}/) found_flag = true end end nil end |
#flags ⇒ Object
782 783 784 785 786 787 788 789 790 |
# File 'lib/hiiro.rb', line 782 def flags @flags ||= proc { raw_args.select { |arg| arg.match?(/^-[^-]/) }.flat_map { |arg| arg.sub(/^-/, '').chars } }.call end |
#values ⇒ Object
811 812 813 814 815 |
# File 'lib/hiiro.rb', line 811 def values raw_args.reject do |arg| arg.match?(/^-/) end end |