Class: Ropet::Parser
- Inherits:
-
Object
- Object
- Ropet::Parser
- Defined in:
- lib/ropet/parser.rb
Overview
Main class for Ropet, handles all injecting logic, parsing flags and setting options
Instance Attribute Summary (collapse)
-
- (Config) config
readonly
Config.
-
- (Hash) settings
readonly
Assigned options.
Class Method Summary (collapse)
- + (Parser) inject(*options) deprecated Deprecated.
- + (Parser) let(&block) deprecated Deprecated.
Instance Method Summary (collapse)
-
- (Object) [](index)
Retrieves value for given `key`.
-
- (Boolean) has_key?(key)
Checks existence of `key` in defined settings or defaults.
-
- (Parser) initialize(config = nil)
constructor
Initializes new parser Sets up @settings.
-
- (Parser) inject(*options)
Main method of Ropet.
Constructor Details
- (Parser) initialize(config = nil)
Initializes new parser Sets up @settings
16 17 18 19 20 21 |
# File 'lib/ropet/parser.rb', line 16 def initialize(config = nil) @settings = {} @config = config || Config.new return self end |
Instance Attribute Details
- (Config) config (readonly)
Config
11 12 13 |
# File 'lib/ropet/parser.rb', line 11 def config @config end |
- (Hash) settings (readonly)
Assigned options
8 9 10 |
# File 'lib/ropet/parser.rb', line 8 def settings @settings end |
Class Method Details
+ (Parser) inject(*options)
Deprecated.
Creates new Parser with default Config. Calls Parser#inject on `*options`.
63 64 65 66 |
# File 'lib/ropet/parser.rb', line 63 def self.inject(*) obj = self.new(Config.new) obj.inject end |
+ (Parser) let(&block)
Deprecated.
Creates new Parser with a block of dsl methods to pass for Config initialization
28 29 30 |
# File 'lib/ropet/parser.rb', line 28 def self.let(&block) self.new(Config.from_dsl(&block)) end |
Instance Method Details
- (Object) [](index)
Retrieves value for given `key`.
80 81 82 83 84 85 86 87 |
# File 'lib/ropet/parser.rb', line 80 def [](index) index = index.to_sym unless @settings[index] == nil @settings[index] else config.defaults[index] end end |
- (Boolean) has_key?(key)
Checks existence of `key` in defined settings or defaults.
72 73 74 75 |
# File 'lib/ropet/parser.rb', line 72 def has_key?(key) key = key.to_sym @settings.has_key?(key) or config.defaults.has_key?(key) end |
- (Parser) inject(*options)
Main method of Ropet. Parses options and flags and stores them properly.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ropet/parser.rb', line 39 def inject(*) .each do |option| if option.is_a?(Symbol) || option.is_a?(String) flag = option.to_s prefix_range = 0...(config.false_prefix.length) if flag[prefix_range] == config.false_prefix flag.slice! prefix_range # remove prefix from string if it exists there @settings[flag.to_sym] = false else @settings[option] = true end elsif option.is_a? Hash @settings.merge! option end end return self end |