Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/r_path.rb,
lib/auto_object.rb,
lib/blank_slate.rb,
lib/sym_tbl_gsub.rb,
lib/verbose_object.rb,
lib/yaml_extensions/transform.rb
Overview
FIXME: Implement all ruby types.
Class Method Summary collapse
Instance Method Summary collapse
- #auto_object? ⇒ Boolean
- #blank_slate? ⇒ Boolean
- #do_symtbl_gsub(symtbl) ⇒ Object
- #do_symtbl_gsub!(symtbl) ⇒ Object
-
#regex_path_match(re, trees, args, &block) ⇒ Object
:nodoc:.
-
#rpath(re, &block) ⇒ Object
RPath is a sort of the well known XPath.
-
#rpath_find(mode, re) ⇒ Object
mode = [:first, :all] rpath_find :all is like rpath_select rpath_find :first is the first element of rpath_select.
-
#rpath_select(re) ⇒ Object
Act like rpath it does not take a block but.
-
#rpath_select_match_data(re) ⇒ Object
Like rpath_select with match datas.
- #symtbl_gsub(symtbl) ⇒ Object
- #symtbl_gsub!(symtbl) ⇒ Object
- #symtbl_to_s ⇒ Object
- #verbose_object? ⇒ Boolean
- #verbosify(opts = nil) ⇒ Object
- #verbosify!(opts = nil) ⇒ Object
-
#yaml_doc_traverse(activated) ⇒ Object
:nodoc:.
Class Method Details
.blank_slate_ignore(name) ⇒ Object
68 69 70 |
# File 'lib/blank_slate.rb', line 68 def self.blank_slate_ignore ( name ) name =~ /^(__|blank_slate\?$)/ end |
Instance Method Details
#auto_object? ⇒ Boolean
50 51 52 |
# File 'lib/auto_object.rb', line 50 def auto_object? false end |
#blank_slate? ⇒ Boolean
72 73 74 |
# File 'lib/blank_slate.rb', line 72 def blank_slate? false end |
#do_symtbl_gsub(symtbl) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/sym_tbl_gsub.rb', line 46 def do_symtbl_gsub ( symtbl ) unless symtbl.is_a? SymTbl raise ArgumentError, "need a SymTbl not: #{symtbl.inspect}" end result = symtbl_gsub(symtbl) return (result.nil?)? self : result end |
#do_symtbl_gsub!(symtbl) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/sym_tbl_gsub.rb', line 54 def do_symtbl_gsub! ( symtbl ) unless symtbl.is_a? SymTbl raise ArgumentError, "need a SymTbl not: #{symtbl.inspect}" end result = symtbl_gsub!(symtbl) return (result.nil?)? self : result end |
#regex_path_match(re, trees, args, &block) ⇒ Object
:nodoc:
105 106 107 |
# File 'lib/r_path.rb', line 105 def regex_path_match ( re, trees, args, &block ) # :nodoc: to_s.regex_path_match(re, trees, args, &block) end |
#rpath(re, &block) ⇒ Object
RPath is a sort of the well known XPath. XPath is XML and RPath is obviously built for Ruby.
When you have a Ruby tree – by tree I mean a complex data structure with no cycles – you can search something into it:
tree = {
:A => {
:AA => { :AAA => 'foo' },
'AB' => [ :AB1, 2, 'a b 3' ],
},
:B => {
'foo' => { :home => 'here', :email => '[email protected]' },
'bar' => { :home => "bar's home", :email => '[email protected]' },
'baz' => { :home => 'nowhere', :email => '[email protected]' }
}
}
tree.rpath(‘/A/AA/AAA/’) { |x| p x } # => ‘foo’
But we are dealing with regexp so if you want just this path you need: tree.rpath(‘/^A$/^AA$/^AAA$/’) { |x| p x } # => ‘foo’
But if you are lazy you can type that: tree.rpath(‘/A/AA//’) { |x| p x } # => ‘foo’ or tree.rpath(‘///AAA/’) { |x| p x } # => ‘foo’
tree.rpath(‘/B//home/nowhere’) { |x| p x } # => ‘nowhere’
But you would prefer get the complete baz record, so to do that you can mark your dezired levels with ‘()’.
tree.rpath(‘/B//()home/nowhere’) { |x| p x } # => ‘[email protected]’
tree.rpath(‘/B//()home/ere’) { |x| p x }
> ‘[email protected]’
> ‘[email protected]’
tree.rpath(‘/B//()home/(.*)’) { |tree, home| p [home, tree] }
> [ ‘here’, ‘[email protected]’ ]
> [ “bar’s home”, ‘[email protected]’ ]
> [ ‘nowhere’, ‘[email protected]’ ]
You can negate some parts of your RPath using the ‘!’ modifier:
tree.rpath(‘/B//()home/!ere’) { |x| p x }
> ‘[email protected]’
You can also specify a negative RPath with the ‘N’ tag.
60 61 62 63 64 65 |
# File 'lib/r_path.rb', line 60 def rpath ( re, &block ) raise ArgumentError, 'no block given' unless block_given? re = RegexPath.new(re) unless re.is_a? RegexPath regex_path_match(re, nil, [], &block) nil end |
#rpath_find(mode, re) ⇒ Object
mode = [:first, :all] rpath_find :all is like rpath_select rpath_find :first is the first element of rpath_select
96 97 98 99 100 101 102 103 |
# File 'lib/r_path.rb', line 96 def rpath_find ( mode, re ) results = rpath_select(re) case mode when :all then results when :first then results.first else raise "Bad mode `#{mode}' for rpath_find" end end |
#rpath_select(re) ⇒ Object
Act like rpath it does not take a block but
70 71 72 73 74 75 76 77 |
# File 'lib/r_path.rb', line 70 def rpath_select ( re ) results = [] re = RegexPath.new(re) unless re.is_a? RegexPath regex_path_match(re, nil, []) do |x| results << x end results end |
#rpath_select_match_data(re) ⇒ Object
Like rpath_select with match datas
82 83 84 85 86 87 88 89 |
# File 'lib/r_path.rb', line 82 def rpath_select_match_data ( re ) results = [] re = RegexPath.new(re) unless re.is_a? RegexPath regex_path_match(re, nil, []) do |*a| results << a end results end |
#symtbl_gsub(symtbl) ⇒ Object
42 43 44 |
# File 'lib/sym_tbl_gsub.rb', line 42 def symtbl_gsub ( symtbl ) nil end |
#symtbl_gsub!(symtbl) ⇒ Object
38 39 40 |
# File 'lib/sym_tbl_gsub.rb', line 38 def symtbl_gsub! ( symtbl ) nil end |
#symtbl_to_s ⇒ Object
62 63 64 |
# File 'lib/sym_tbl_gsub.rb', line 62 def symtbl_to_s to_json end |
#verbose_object? ⇒ Boolean
105 106 107 |
# File 'lib/verbose_object.rb', line 105 def verbose_object? false end |
#verbosify(opts = nil) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/verbose_object.rb', line 109 def verbosify ( opts=nil ) begin verbosify!(opts) rescue TypeError => ex VerboseObject.new(self, opts) end end |
#verbosify!(opts = nil) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/verbose_object.rb', line 117 def verbosify! ( opts=nil ) unless blank_slate? class << self def self.blank_slate_ignore ( name ) VerboseObject.blank_slate_ignore(name) end end extend BlankSlate unless blank_slate? end __blank_slate_extend Verbosify unless verbose_object? self. = opts self rescue TypeError => ex raise TypeError, "can't make a verbose object from #{self} (#{ex})" end |
#yaml_doc_traverse(activated) ⇒ Object
:nodoc:
27 28 29 |
# File 'lib/yaml_extensions/transform.rb', line 27 def yaml_doc_traverse ( activated ) raise ArgumentError, "can't traverse class #{self.class}" end |