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.



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

def initialize(*raw_args)
  @raw_args = raw_args
end

Instance Attribute Details

#raw_argsObject (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

Returns:

  • (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

#flagsObject



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

#valuesObject



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

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