Class: Array

Inherits:
Object show all
Defined in:
lib/sdbcli/sdb-runner.rb

Overview

XXX:

Instance Method Summary collapse

Instance Method Details

#as_rowObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sdbcli/sdb-runner.rb', line 44

def as_row
  row = self.dup

  def row.method_missing(method_name, *args, &block)
    case method_name.to_s
    when /itemName/i
      self[0]
    when /=\Z/
      self[1][method_name.to_s.sub(/=\Z/, '')] = (args.length > 2) ? args : args[0]
    else
      self[1][method_name.to_s]
    end
  end

  return row
end

#as_row!Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sdbcli/sdb-runner.rb', line 61

def as_row!
  row = self

  def row.method_missing(method_name, *args, &block)
    case method_name.to_s
    when /itemName/i
      self[0]
    when /=\Z/
      self[1][method_name.to_s.sub(/=\Z/, '')] = (args.length > 2) ? args : args[0]
    else
      self[1][method_name.to_s]
    end
  end

  return row
end

#as_rowsObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/sdbcli/sdb-runner.rb', line 78

def as_rows
  rows = self.dup

  def rows.method_missing(method_name, *args, &block)
    case method_name.to_s
    when /itemName/i
      self.map {|i| i[0] }
    when /=\Z/
      self.each do |i|
        i[1][method_name.to_s.sub(/=\Z/, '')] = (args.length > 2) ? args : args[0]
      end
      self
    else
      self.map {|i| i[1][method_name.to_s] }
    end
  end

  return rows
end

#as_rows!Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sdbcli/sdb-runner.rb', line 98

def as_rows!
  rows = self

  def rows.method_missing(method_name, *args, &block)
    case method_name.to_s
    when /itemName/i
      self.map {|i| i[0] }
    when /=\Z/
      self.each do |i|
        i[1][method_name.to_s.sub(/=\Z/, '')] = (args.length > 2) ? args : args[0]
      end
      self
    else
      self.map {|i| i[1][method_name.to_s] }
    end
  end

  return rows
end

#avgObject



40
41
42
# File 'lib/sdbcli/sdb-runner.rb', line 40

def avg
  self.sum / self.length
end

#inlineObject



118
119
120
121
122
# File 'lib/sdbcli/sdb-runner.rb', line 118

def inline
  obj = self.dup
  def obj.to_yaml_style; :inline; end
  return obj
end

#inline!Object



124
125
126
127
128
# File 'lib/sdbcli/sdb-runner.rb', line 124

def inline!
  obj = self
  def obj.to_yaml_style; :inline; end
  return obj
end

#sumObject



36
37
38
# File 'lib/sdbcli/sdb-runner.rb', line 36

def sum
  self.inject {|r, i| r + i }
end

#to_fObject



32
33
34
# File 'lib/sdbcli/sdb-runner.rb', line 32

def to_f
  self.map {|i| i.to_f }
end

#to_iObject



28
29
30
# File 'lib/sdbcli/sdb-runner.rb', line 28

def to_i
  self.map {|i| i.to_i }
end