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.
780 781 782 |
# File 'lib/hiiro.rb', line 780 def initialize(*raw_args) @raw_args = raw_args end |
Instance Attribute Details
#raw_args ⇒ Object (readonly)
Returns the value of attribute raw_args.
778 779 780 |
# File 'lib/hiiro.rb', line 778 def raw_args @raw_args end |
Instance Method Details
#flag?(flag) ⇒ Boolean
794 795 796 |
# File 'lib/hiiro.rb', line 794 def flag?(flag) flags.include?(flag) end |
#flag_value(flag) ⇒ Object
798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'lib/hiiro.rb', line 798 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
784 785 786 787 788 789 790 791 792 |
# File 'lib/hiiro.rb', line 784 def flags @flags ||= proc { raw_args.select { |arg| arg.match?(/^-[^-]/) }.flat_map { |arg| arg.sub(/^-/, '').chars } }.call end |
#values ⇒ Object
813 814 815 816 817 |
# File 'lib/hiiro.rb', line 813 def values raw_args.reject do |arg| arg.match?(/^-/) end end |