Module: LitaGithub::General
- Defined in:
- lib/lita-github/general.rb
Overview
Github handler common-use methods
Instance Method Summary collapse
-
#opts_parse(cmd) ⇒ Hash
Parse the options in the command using the option regex.
-
#symbolize_opt_key(k, v) ⇒ Array
For use when parsing options using
opt_parse()
, this method converts the key to a downcased symbol for use within the option Hash. -
#to_i_if_numeric(value) ⇒ Integer, String
Convert the value of parameter 1 to an Integer if it looks like it should be one.
Instance Method Details
#opts_parse(cmd) ⇒ Hash
Parse the options in the command using the option regex
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lita-github/general.rb', line 50 def opts_parse(cmd) o = {} cmd.scan(LitaGithub::R::OPT_REGEX).flatten.each do |opt| k, v = symbolize_opt_key(*opt.strip.split(':')) next if o.key?(k) # if it looks like we're using the extended option (first character is a " or '): # slice off the first and last character of the string # otherwise: # do nothing v = v.slice!(1, (v.length - 2)) if %w(' ").include?(v.slice(0)) o[k] = to_i_if_numeric(v) end o end |
#symbolize_opt_key(k, v) ⇒ Array
For use when parsing options using opt_parse()
, this method converts the key to a downcased symbol for use within the option Hash.
41 42 43 |
# File 'lib/lita-github/general.rb', line 41 def symbolize_opt_key(k, v) [k.downcase.to_sym, v] end |
#to_i_if_numeric(value) ⇒ Integer, String
Convert the value of parameter 1 to an Integer if it looks like it should be one
30 31 32 |
# File 'lib/lita-github/general.rb', line 30 def to_i_if_numeric(value) /^\d+$/.match(value) ? value.to_i : value end |