rbbt-util 5.0.1 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -521,8 +521,8 @@ module TSV
521
521
  @monitor = old_monitor
522
522
 
523
523
  if not fields.nil? and not name.nil?
524
- fields = self.fields + [name]
525
- self.fields = fields
524
+ new_fields = self.fields + [name]
525
+ self.fields = new_fields
526
526
  end
527
527
 
528
528
  self
@@ -306,7 +306,7 @@ module TSV
306
306
  merge = Misc.process_options(options, :merge) || false
307
307
 
308
308
  @sep2 = Misc.process_options(options, :sep2) || "|"
309
- @cast = Misc.process_options options, :cast
309
+ @cast = Misc.process_options options, :cast; @cast = @cast.to_sym if String === @cast
310
310
  @type ||= Misc.process_options options, :type
311
311
  @fix = Misc.process_options(options, :fix)
312
312
  @select= Misc.process_options options, :select
@@ -101,12 +101,13 @@ module Misc
101
101
  end
102
102
 
103
103
  def self.prepare_entity(entity, field, options = {})
104
+ return entity unless defined? Entity
104
105
  return entity unless String === entity or Array === entity
105
106
  options ||= {}
106
107
 
107
108
  dup_array = options.delete :dup_array
108
109
 
109
- if defined?(Entity) and Entity.respond_to?(:formats) and Entity.formats.include? field
110
+ if Entity.respond_to?(:formats) and Entity.formats.include? field
110
111
  params = options.dup
111
112
 
112
113
  params[:format] ||= params.delete "format"
@@ -120,7 +121,7 @@ module Misc
120
121
 
121
122
  entity
122
123
  end
123
-
124
+
124
125
  ARRAY_MAX_LENGTH = 10000
125
126
  STRING_MAX_LENGTH = ARRAY_MAX_LENGTH * 10
126
127
 
@@ -641,7 +642,7 @@ end
641
642
  next unless %w(Symbol String Float Fixnum Integer TrueClass FalseClass Module Class Object Array).include? v.class.to_s
642
643
  v = case
643
644
  when Symbol === v
644
- ":" << v.to_s
645
+ v.to_s
645
646
  when Array === v
646
647
  v * ","
647
648
  else
@@ -17,6 +17,32 @@ module NamedArray
17
17
  array
18
18
  end
19
19
 
20
+ def prepare_entity(entity, field, options = {})
21
+ return entity if entity.nil?
22
+ return entity unless defined? Entity
23
+ @entity_templates ||= {}
24
+ if (template = @entity_templates[field])
25
+ entity = template.annotate(entity.frozen? ? entity.dup : entity)
26
+ entity.extend AnnotatedArray if Array === entity
27
+ entity
28
+ else
29
+ if @entity_templates.include? field
30
+ entity
31
+ else
32
+ template = Misc.prepare_entity("TEMPLATE", field, options)
33
+ if Annotated === template
34
+ @entity_templates[field] = template
35
+ entity = template.annotate(entity.frozen? ? entity.dup : entity)
36
+ entity.extend AnnotatedArray if Array === entity
37
+ entity
38
+ else
39
+ @entity_templates[field] = nil
40
+ entity
41
+ end
42
+ end
43
+ end
44
+ end
45
+
20
46
  def merge(array)
21
47
  double = Array === array.first
22
48
  new = self.dup
@@ -47,14 +73,14 @@ module NamedArray
47
73
  return elem if @fields.nil? or @fields.empty?
48
74
 
49
75
  field = NamedArray === @fields ? @fields.named_array_clean_get_brackets(pos) : @fields[pos]
50
- elem = Misc.prepare_entity(elem, field, entity_options)
76
+ elem = prepare_entity(elem, field, entity_options)
51
77
  elem
52
78
  end
53
79
 
54
80
  def named_array_each(&block)
55
81
  if defined?(Entity) and not @fields.nil? and not @fields.empty?
56
82
  @fields.zip(self).each do |field,elem|
57
- elem = Misc.prepare_entity(elem, field, entity_options)
83
+ elem = prepare_entity(elem, field, entity_options)
58
84
  yield(elem)
59
85
  elem
60
86
  end
@@ -254,7 +254,7 @@ module Workflow
254
254
  if inputs.any? or dependencies.any?
255
255
  tagged_jobname = case TAG
256
256
  when :hash
257
- jobname + '_' + Misc.digest((inputs + dependencies.collect{|dep| dep.name}).inspect)
257
+ jobname + '_' + Misc.digest((inputs * "\n" + ";" + dependencies.collect{|dep| dep.name} * "\n"))
258
258
  else
259
259
  jobname
260
260
  end
@@ -45,9 +45,20 @@ class Step
45
45
  end
46
46
 
47
47
  def prepare_result(value, description = nil, info = {})
48
- return value if description.nil?
49
- Entity.formats[description].setup(value, info.merge(:format => description)) if defined?(Entity) and Entity.respond_to?(:formats) and Entity.formats.include? description
50
- value
48
+ case
49
+ when (not defined? Entity or description.nil? or not Entity.formats.include? description)
50
+ value
51
+ when (Annotated === value and info.empty?)
52
+ value
53
+ when Annotated === value
54
+ annotations = value.annotations
55
+ info.each do |k,v|
56
+ value.send("#{h}=", v) if annotations.include? k
57
+ end
58
+ value
59
+ else
60
+ Entity.formats[description].setup(value, info.merge(:format => description))
61
+ end
51
62
  end
52
63
 
53
64
  def exec
@@ -17,6 +17,7 @@ module AnnotatedString2
17
17
  include AnnotatedString
18
18
  self.annotation :annotation_str2
19
19
  end
20
+ puts AnnotatedString.annotations.inspect
20
21
 
21
22
  class TestAnnotations < Test::Unit::TestCase
22
23
 
@@ -61,7 +62,7 @@ class TestAnnotations < Test::Unit::TestCase
61
62
  annotation_str = "Annotation String"
62
63
  AnnotatedString.setup(ary, annotation_str)
63
64
 
64
- assert_equal({:annotation_str => annotation_str, :annotation_types => [AnnotatedString]}, ary.info)
65
+ assert_equal({:annotation_str => annotation_str, :annotation_types => [AnnotatedString], :annotated_array => true}, ary.info)
65
66
  end
66
67
 
67
68
  def test_load
@@ -89,7 +90,10 @@ class TestAnnotations < Test::Unit::TestCase
89
90
  annotation_str2 = "Annotation String 2"
90
91
  AnnotatedString.setup(str1, annotation_str1)
91
92
  AnnotatedString.setup(str2, annotation_str2)
93
+
94
+ assert_equal annotation_str1, Annotated.tsv([str1, str2], :all)[str1.id + ":0"]["annotation_str"]
92
95
  assert_equal str1, Annotated.tsv([str1, str2], :all)[str1.id + ":0"]["literal"]
96
+ assert_equal annotation_str1, Annotated.tsv([str1, str2], :all)[str1.id + ":0"]["annotation_str"]
93
97
  assert_equal annotation_str1, Annotated.tsv([str1, str2], :annotation_str, :JSON)[str1.id + ":0"]["annotation_str"]
94
98
  end
95
99
 
@@ -129,7 +133,6 @@ class TestAnnotations < Test::Unit::TestCase
129
133
  str = "string1"
130
134
  annotation_str1 = "Annotation String 1"
131
135
  annotation_str2 = "Annotation String 2"
132
- assert_equal [AnnotatedString], AnnotatedString2.inheritance
133
136
  AnnotatedString2.setup(str, annotation_str1, annotation_str2)
134
137
  assert_equal annotation_str1, str.annotation_str
135
138
  assert_equal annotation_str2, str.annotation_str2
@@ -147,8 +150,9 @@ class TestAnnotations < Test::Unit::TestCase
147
150
  b = AnnotatedString.setup([AnnotatedString.setup(["a"])])
148
151
  AnnotatedString.setup(a)
149
152
  a.extend AnnotatedArray
150
- b.extend AnnotatedArray
151
153
  assert AnnotatedString === b[0]
154
+ b.extend AnnotatedArray
155
+ assert AnnotatedString === b[0, true]
152
156
  assert(!a.double_array)
153
157
  assert(b.double_array)
154
158
  end
@@ -118,7 +118,6 @@ row3 A a|B Id4
118
118
 
119
119
  TmpFile.with_file(content) do |filename|
120
120
  index = TSV.index(filename, :target => "OtherID", :data_sep => /\s+/, :order => true, :persist => false)
121
- ddd index
122
121
  assert_equal "Id1", index['a']
123
122
  assert_equal "Id3", index['A']
124
123
  assert_equal "OtherID", index.fields.first
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -174,6 +174,8 @@ files:
174
174
  - lib/rbbt-util.rb
175
175
  - lib/rbbt.rb
176
176
  - lib/rbbt/annotations.rb
177
+ - lib/rbbt/annotations/annotated_array.rb
178
+ - lib/rbbt/annotations/util.rb
177
179
  - lib/rbbt/fix_width_table.rb
178
180
  - lib/rbbt/persist.rb
179
181
  - lib/rbbt/persist/tsv.rb