Class: Plist4r::Backend::Test::DataTypes

Defined in:
lib/plist4r/backend/test/data_types.rb

Instance Methods

Constant Summary

PlistDataTypes =
[:bool, :integer, :float, :string, :time, :array, :hash, :data]

Constructor Details

- (DataTypes) initialize(*args, &blk)

A new instance of DataTypes



9
10
11
12
13
14
15
16
17
18
# File 'lib/plist4r/backend/test/data_types.rb', line 9

def initialize *args, &blk
  @plists = Plist4r::OrderedHash.new
  PlistDataTypes.each do |pdt|
    @plist = Plist4r.new
    self.send "gen_#{pdt}"
    @plists[pdt] = @plist
  end
  
  @plist_1024 = gen_plist_1024
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(meth, *args, &blk)



20
21
22
# File 'lib/plist4r/backend/test/data_types.rb', line 20

def method_missing meth, *args, &blk
  @plists[meth] if PlistDataTypes.include?(meth)
end

Instance Method Details

- (Object) gen_array



75
76
77
78
79
80
81
82
83
# File 'lib/plist4r/backend/test/data_types.rb', line 75

def gen_array
  (0..25).each do |i|
    a = []
    (0..i).each do |j|
      a << "String#{(65+j).chr}"
    end
    @plist.store "ArrayKey#{(65+i).chr}", a
  end
end

- (Object) gen_bool



32
33
34
35
36
# File 'lib/plist4r/backend/test/data_types.rb', line 32

def gen_bool
  [true,false].each do |bool|
    @plist.store "BoolKey#{bool.to_s.capitalize}", bool
  end
end

- (Object) gen_data



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/plist4r/backend/test/data_types.rb', line 63

def gen_data
  # a = []
  (0..25).each do |i|
    s = "1"*i
    bstr = "DataBytes#{s}"
    bstr.blob = true
    @plist.store "DataKey#{(65+i).chr}", bstr
    # a << bstr
  end
  # @plist.store "BinaryArray", a
end

- (Object) gen_float



44
45
46
47
48
# File 'lib/plist4r/backend/test/data_types.rb', line 44

def gen_float
  (0..100).each do |i|
    @plist.store "RealKey#{i}", i.to_f / 100
  end
end

- (Object) gen_hash



85
86
87
88
89
90
91
92
93
94
# File 'lib/plist4r/backend/test/data_types.rb', line 85

def gen_hash
  (0..25).each do |i|
    h = Plist4r::OrderedHash.new
    # (0..0).each do |j|
    (0..i).each do |j|
      h["String#{(65+j).chr}"] = "#{(97+j).chr}"*(j+1)
    end
    @plist.store "HashKey#{(65+i).chr}", h
  end
end

- (Object) gen_integer



38
39
40
41
42
# File 'lib/plist4r/backend/test/data_types.rb', line 38

def gen_integer
  (0..9).each do |i|
    @plist.store "IntegerKey#{(65+i).chr}", i
  end
end

- (Object) gen_mixed



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/plist4r/backend/test/data_types.rb', line 96

def gen_mixed
  @plist.edit do
    [true,false].each do |bool|
      store "BoolKey#{bool.to_s.capitalize}", bool
    end

    (0..9).each do |i|
      store "IntegerKey#{(65+i).chr}", i
    end

    (0..25).each do |i|
      store "StringKey#{(65+i).chr}", "#{(97+i).chr}"*(i+1)
    end

    (0..25).each do |i|
      a = []
      (0..i).each do |j|
        a << "String#{(65+j).chr}"
      end
      store "ArrayKey#{(65+i).chr}", a
    end

    (0..25).each do |i|
      h = Plist4r::OrderedHash.new
      (0..i).each do |j|
        h["String#{(65+j).chr}"] = "#{(97+j).chr}"*(j+1)
      end
      store "HashKey#{(65+i).chr}", h
    end
  end
end

- (Object) gen_plist_1024



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/plist4r/backend/test/data_types.rb', line 128

def gen_plist_1024
  @plist_1024 ||= Plist4r.new do
    coarse_multiplier = 18
    (0..coarse_multiplier).each do |i|

      a = []
      (0..25).each do |j|
        a << "String#{(65+j).chr}"
      end
      store "ArrayKey#{i}", a

      h = Plist4r::OrderedHash.new
      (0..25).each do |j|
        h["String#{(65+j).chr}"] = "#{(97+j).chr}"*(j+1)
      end
      store "HashKey#{i}", h
    end

    a = []
    (0..11).each do |j|
      a << "String#{(65+j).chr}"
    end
    store "ArrayKeyPad1", a

    a = []
    (0..23).each do |j|
      a << "String#{(65+j).chr}"
    end
    store "ArrayKeyPad2", a
  end
  @plist_1024
end

- (Object) gen_string



50
51
52
53
54
# File 'lib/plist4r/backend/test/data_types.rb', line 50

def gen_string
  (0..25).each do |i|
    @plist.store "StringKey#{(65+i).chr}", "#{(97+i).chr}"*(i+1)
  end
end

- (Object) gen_time



56
57
58
59
60
61
# File 'lib/plist4r/backend/test/data_types.rb', line 56

def gen_time
  require 'time'
  (0..25).each do |i|
    @plist.store "DateKey#{(65+i).chr}", Time.parse("2010-04-#{sprintf("%.2i",i+1)}T19:50:01Z")
  end
end

- (Object) plist_1024



28
29
30
# File 'lib/plist4r/backend/test/data_types.rb', line 28

def plist_1024
  @plist_1024
end

- (Object) plists



24
25
26
# File 'lib/plist4r/backend/test/data_types.rb', line 24

def plists
  @plists
end