Class: Hiiro::Args

Inherits:
Object
  • Object
show all
Defined in:
lib/hiiro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*raw_args) ⇒ Args

Returns a new instance of Args.



779
780
781
# File 'lib/hiiro.rb', line 779

def initialize(*raw_args)
  @raw_args = raw_args
end

Instance Attribute Details

#raw_argsObject (readonly)

Returns the value of attribute raw_args.



777
778
779
# File 'lib/hiiro.rb', line 777

def raw_args
  @raw_args
end

Instance Method Details

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)


793
794
795
# File 'lib/hiiro.rb', line 793

def flag?(flag)
  flags.include?(flag)
end

#flag_value(flag) ⇒ Object



797
798
799
800
801
802
803
804
805
806
807
808
809
810
# File 'lib/hiiro.rb', line 797

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

#flagsObject



783
784
785
786
787
788
789
790
791
# File 'lib/hiiro.rb', line 783

def flags
  @flags ||= proc {
    raw_args.select { |arg|
      arg.match?(/^-[^-]/)
    }.flat_map { |arg|
      arg.sub(/^-/, '').chars
    }
  }.call
end

#valuesObject



812
813
814
815
816
# File 'lib/hiiro.rb', line 812

def values
  raw_args.reject do |arg|
    arg.match?(/^-/)
  end
end