textutils 0.9.5 → 0.9.6
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.
- data/Rakefile +1 -0
- data/lib/textutils.rb +3 -0
- data/lib/textutils/reader/fixture_reader.rb +39 -36
- data/lib/textutils/reader/values_reader.rb +62 -13
- data/lib/textutils/version.rb +1 -3
- metadata +23 -12
data/Rakefile
CHANGED
data/lib/textutils.rb
CHANGED
@@ -6,28 +6,55 @@
|
|
6
6
|
|
7
7
|
##
|
8
8
|
# use ManifestReader ?? why? why not? - reuse in manifest gem (or manman e.g. manifest manger) ??
|
9
|
-
#
|
9
|
+
#
|
10
10
|
|
11
11
|
class FixtureReader
|
12
12
|
|
13
13
|
include LogUtils::Logging
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
|
16
|
+
def self.from_zip( zip_file, name )
|
17
|
+
|
18
|
+
## fix: check if name ends in .txt ?? if not add .txt
|
19
|
+
## change name to path ?? e.g. make it required to pass in full entry path??
|
20
|
+
### fix -fix -fix => change name to path
|
21
|
+
|
22
|
+
path = name.end_with?('.txt') ? name : "#{name}.txt"
|
23
|
+
|
24
|
+
## get text content from zip
|
25
|
+
text = zip_file.read( path )
|
26
|
+
self.from_string( text )
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.from_file( path )
|
30
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
31
|
+
## - see textutils/utils.rb
|
32
|
+
text = File.read_utf8( path )
|
33
|
+
self.from_string( text )
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.from_string( text )
|
37
|
+
FixtureReader.new( { text: text } )
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def initialize( arg )
|
42
|
+
|
43
|
+
if arg.is_a?( String ) ## old style (deprecated) - pass in filepath as string
|
44
|
+
path = arg
|
45
|
+
logger.info "FixtureReader.new - deprecated API - use FixtureReader.from_file() instead"
|
46
|
+
text = File.read_utf8( path )
|
47
|
+
else ## assume it's a hash
|
48
|
+
opts = arg
|
49
|
+
text = opts[:text]
|
50
|
+
end
|
51
|
+
|
18
52
|
@ary = []
|
19
53
|
|
20
54
|
## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
21
55
|
## - see textutils/utils.rb
|
22
|
-
text = File.read_utf8( @path )
|
23
56
|
|
24
|
-
|
25
|
-
### fix/todo: remove later on!!! - do not use!!
|
26
|
-
puts "deprecated api - FixtureReader w/ yaml format - will get removed; please use new plain text manifest format"
|
27
|
-
@ary = old_deprecated_yaml_reader( text )
|
28
|
-
else
|
29
|
-
@ary = plain_text_reader( text )
|
30
|
-
end
|
57
|
+
@ary = plain_text_reader( text )
|
31
58
|
|
32
59
|
logger.debug "fixture setup:"
|
33
60
|
logger.debug @ary.to_json
|
@@ -75,30 +102,6 @@ class FixtureReader
|
|
75
102
|
end # method plain_text_reader
|
76
103
|
|
77
104
|
|
78
|
-
def old_deprecated_yaml_reader( text )
|
79
|
-
hash = YAML.load( text )
|
80
|
-
|
81
|
-
### build up array for fixtures from hash
|
82
|
-
ary = []
|
83
|
-
|
84
|
-
hash.each do |key_wild, value_wild|
|
85
|
-
key = key_wild.to_s.strip
|
86
|
-
|
87
|
-
logger.debug "yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value_wild}<<"
|
88
|
-
|
89
|
-
if value_wild.kind_of?( String ) # assume single fixture name
|
90
|
-
ary << value_wild
|
91
|
-
elsif value_wild.kind_of?( Array ) # assume array of fixture names as strings
|
92
|
-
ary = ary + value_wild
|
93
|
-
else
|
94
|
-
logger.error "unknow fixture type in setup (yaml key:#{key_wild.class.name} >>#{key}<<, value:#{value_wild.class.name} >>#{value_wild}<<); skipping"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
ary # return fixture ary
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
105
|
def each
|
103
106
|
@ary.each do |fixture|
|
104
107
|
yield( fixture )
|
@@ -6,24 +6,73 @@
|
|
6
6
|
class ValuesReader
|
7
7
|
|
8
8
|
include LogUtils::Logging
|
9
|
-
|
9
|
+
|
10
10
|
include TextUtils::ValueHelper # e.g. includes find_grade, find_key_n_title
|
11
11
|
|
12
12
|
|
13
|
-
def
|
13
|
+
def self.from_zip( zip_file, name, more_attribs={} )
|
14
|
+
## fix: check if name ends in .txt ?? if not add .txt
|
15
|
+
## change name to path ?? e.g. make it required to pass in full entry path??
|
16
|
+
### fix -fix -fix => change name to path
|
17
|
+
|
18
|
+
path = name.end_with?('.txt') ? name : "#{name}.txt"
|
19
|
+
|
20
|
+
## fix: move out of from_zip
|
21
|
+
# map name to name_real_path
|
22
|
+
# name might include !/ for virtual path (gets cut off)
|
23
|
+
# e.g. at-austria!/w-wien/beers becomse w-wien/beers
|
24
|
+
|
25
|
+
pos = path.index( '!/')
|
26
|
+
if pos.nil?
|
27
|
+
real_path = path # not found; real path is the same as name
|
28
|
+
else
|
29
|
+
# cut off everything until !/ e.g.
|
30
|
+
# at-austria!/w-wien/beers becomes
|
31
|
+
# w-wien/beers
|
32
|
+
real_path = path[ (pos+2)..-1 ]
|
33
|
+
end
|
34
|
+
|
35
|
+
## get text content from zip
|
36
|
+
text = zip_file.read( real_path )
|
37
|
+
|
38
|
+
self.from_string( text, more_attribs )
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.from_file( path, more_attribs={} )
|
42
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
43
|
+
## - see textutils/utils.rb
|
44
|
+
text = File.read_utf8( path )
|
45
|
+
|
46
|
+
self.from_string( text, more_attribs )
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.from_string( text, more_attribs={} )
|
50
|
+
ValuesReader.new( {text: text}, more_attribs )
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def initialize( arg, more_attribs={} )
|
14
55
|
@more_attribs = more_attribs
|
15
56
|
|
16
|
-
###
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
57
|
+
### todo/fix: rename @data to @text !!!!
|
58
|
+
|
59
|
+
if arg.is_a?( String ) ## old style (deprecated) - pass in filepath as string
|
60
|
+
path = arg
|
61
|
+
|
62
|
+
### workaround/hack
|
63
|
+
# if path includes newline assume it's a string buffer not a file name
|
64
|
+
# fix: use from_file an from_string etc. for ctor
|
65
|
+
# check what is the best convention (follow ???)
|
66
|
+
if path =~ /\n/m
|
67
|
+
logger.info "ValuesReader.new - deprecated API - use ValuesReader.from_string() instead"
|
68
|
+
@data = path.dup # make a duplicate ?? why? why not?
|
69
|
+
else
|
70
|
+
logger.info "ValuesReader.new - deprecated API - use ValuesReader.from_file() instead"
|
71
|
+
@data = File.read_utf8( @path )
|
72
|
+
end
|
73
|
+
else ## assume it's a hash
|
74
|
+
opts = arg
|
75
|
+
@data = opts[:text]
|
27
76
|
end
|
28
77
|
end
|
29
78
|
|
data/lib/textutils/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: props
|
16
|
-
requirement: &
|
16
|
+
requirement: &79637680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *79637680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: logutils
|
27
|
-
requirement: &
|
27
|
+
requirement: &79637460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,21 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *79637460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rubyzip
|
38
|
+
requirement: &79635290 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *79635290
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: activesupport
|
38
|
-
requirement: &
|
49
|
+
requirement: &79634910 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :runtime
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *79634910
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: rdoc
|
49
|
-
requirement: &
|
60
|
+
requirement: &79634540 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '4.0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *79634540
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: hoe
|
60
|
-
requirement: &
|
71
|
+
requirement: &79634160 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,7 +76,7 @@ dependencies:
|
|
65
76
|
version: '3.12'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *79634160
|
69
80
|
description: textutils - Text Filters, Helpers, Readers and More
|
70
81
|
email: ruby-talk@ruby-lang.org
|
71
82
|
executables: []
|