Class: Hash

Inherits:
Object show all
Includes:
Diff, PpHierarchy
Defined in:
lib/pp_hierarchy.rb,
lib/diff.rb,
lib/choose.rb,
lib/o_hash.rb,
lib/r_path.rb,
lib/sym_tbl_gsub.rb,
lib/yaml_extensions/transform.rb

Overview

:nodoc:

Direct Known Subclasses

OHash

Instance Method Summary collapse

Methods included from PpHierarchy

#pp_hierarchy

Methods included from Diff

#diff, #gen_diff

Instance Method Details

#choose(limit = nil, generator = nil) ⇒ Object



39
40
41
# File 'lib/choose.rb', line 39

def choose ( limit=nil, generator=nil )
  self[keys.choose(limit, generator)]
end

#no_diff?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/diff.rb', line 80

def no_diff?
  self[:different] == {} and self[:missing] == {} and self[:additional] == {}
end

#ordered?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'lib/o_hash.rb', line 217

def ordered?
  false
end

#regex_path_match(re, trees, args, &block) ⇒ Object

:nodoc:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/r_path.rb', line 115

def regex_path_match ( re, trees, args, &block ) # :nodoc:
  trees = (trees || []) + [self] if re.captured?

  if re.empty?
    trees ||= [self]
    trees.each { |tree| block[tree, *args] }
  else
    seg, tail_re = re.split
    each do |key, val|
      match_data = seg =~ key.to_s
      if match_data
        sub_args = args + match_data[1..-1]
        val.regex_path_match(tail_re, trees, sub_args, &block)
      elsif re.negative?
        val.regex_path_match(tail_re, trees, args, &block)
      end
    end
  end
end

#symtbl_gsub(symtbl) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sym_tbl_gsub.rb', line 85

def symtbl_gsub symtbl
  changed = false
  res = self.class.new
  each do |k,v|
    new_k = k.symtbl_gsub(symtbl)
    new_v = v.symtbl_gsub(symtbl)
    changed = true if new_k or new_v
    res[new_k || k] = (new_v || v)
  end
  changed ? res : nil
end

#symtbl_gsub!(symtbl) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sym_tbl_gsub.rb', line 72

def symtbl_gsub! symtbl
  res = inject nil do |accu, k, v|
    new_k = k.symtbl_gsub! symtbl
    new_v = v.symtbl_gsub! symtbl
    if new_k
      delete k
      self[new_k] = v
    end
    accu || new_k || new_v
  end
  (res.nil?)? nil : self
end

#yaml_doc_traverse(activated) ⇒ Object

FIXME: Are we sure we want to traverse like that? (by stage)



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/yaml_extensions/transform.rb', line 34

def yaml_doc_traverse ( activated )
  new_activated = []
  sons = []
  self.each do |key, value|
    activated.each do |n|
      new_activated += n.match(key, value)
      sons << value unless value.is_a?(String)
    end
  end
  activated += new_activated
  sons.yaml_doc_traverse(activated)
end