sub_string 1.0.2 → 1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f24f4330db4751b15479abc163eeb99fa4eb124f51d2cfc6f1aa2c0b16f254e
4
- data.tar.gz: 5830d4ec1033b1ba826d0d3dc1d0eaf6eb7b28570d1bdc2dc8989dda55f9aea2
3
+ metadata.gz: be037dc9ea050057d431c3c5802fd2f68bed5cfa9784608b7838c8edff615240
4
+ data.tar.gz: b69983867ce0acd0bd43f13897c9440a6933970f42b8bd94640074960d21895e
5
5
  SHA512:
6
- metadata.gz: d6175f5ec4bf07a048cb8abc5a8924e2ae7f55a0af85fbc55f6b1e988f88d1af8c6bd73130b84bd1b4a8b6138a421a2784bf428ddef3e5ffe204fac453389c82
7
- data.tar.gz: e4bb38538824eaecab3962d13144daae32db992122216d70dc0a6cd73a60bbf01f6f56a4f5f54e13a7f4aa54b25bb8f5c4a9155cdd5daefddcc5390c87522d12
6
+ metadata.gz: 7531ec47934fcfdde76d82dcc3bd171d5550d3be4fa9df127a31e1d8e142932a39e7730829c1bf81183749b3b7b3c2aed37f403452654273f02c3198e14b8c35
7
+ data.tar.gz: fa87ab5c861b9e5c5436e32a4f329a0957d3d80e20ba04871f9bf21c886b17e9edbeaf9f4698bf5195314110b4912ad6c1ec419cd4750f7c6771892e15cd5a97
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ -----
2
+ (Version: 1.1)
3
+ 2019-11-09 Masa Sakano
4
+ * No changes in code but follows the update of the parent SubObject, which added attr getter/setter.
5
+
1
6
  -----
2
7
  (Version: 1.0.2)
3
8
  2019-11-07 Masa Sakano
data/Makefile CHANGED
@@ -20,5 +20,5 @@ test:
20
20
 
21
21
  ## yard2md_afterclean in Gem plain_text https://rubygems.org/gems/plain_text
22
22
  doc:
23
- yard doc; [[ -x ".github" && ( "README.en.rdoc" -nt ".github/README.md" ) ]] && ( ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert ARGF.read' < README.en.rdoc | yard2md_afterclean > .github/README.md ; echo ".github/README.md is updated." ) || exit 0
23
+ yard doc; [[ -x ".github" && ( "README.en.rdoc" -nt ".github/README.md" ) ]] && ( ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert ARGF.read' < README.en.rdoc | yard2md_afterclean > .github/README.md.$$ && ( mv -f .github/README.md.$$ .github/README.md && echo ".github/README.md is updated." ) || ( echo "ERROR: failed to create .github/README.md" >&2 ) ) || exit 0
24
24
 
@@ -3,7 +3,8 @@
3
3
 
4
4
  == Summary
5
5
 
6
- Class {SubString} that expresses Ruby sub-String but taking up negligible memory space, as its instance holds the positional information only. It behaves exactly like String (duck-typing), except destructive modification is prohibited. If the original string is destructively modified, warning is issued.
6
+ Class {SubString} that expresses Ruby sub-String but taking up negligible memory space, as its instance holds the positional information only. It behaves exactly like String (duck-typing), except destructive modification is prohibited. If the original string is destructively modified, warning is issued. Also, as a bonus, an
7
+ arbitrary object can be associated with instances of this class with +SubString#attr+.
7
8
 
8
9
  On the surface, this is a String version of the class MatchSkeleton
9
10
  {match_skeleton}[https://rubygems.org/gems/match_skeleton] (also in
@@ -26,7 +27,7 @@ in {Github}[https://github.com/masasakano/sub_string]
26
27
  This class takes three parameters in the initialization: *source*, *pos*
27
28
  (starting positional character-index), and *size* (of the substring of the original String *source*.
28
29
 
29
- SubObject.new( source, position, size )
30
+ SubString.new( source, index1, index2, attr: arbitrary_object )
30
31
 
31
32
  The constructed instance of this class keeps only these three pieces
32
33
  of information (plus a hash value, strictly speaking), and hence uses negligible internal memory space on its own.
@@ -43,6 +44,12 @@ sub-String object:
43
44
  and works exactly like *source*
44
45
  ({duck-typing}[https://en.wikipedia.org/wiki/Duck_typing]).
45
46
 
47
+ Note +attr+ option is optional and to set an arbitrary object as an
48
+ instance variable. The default value is nil. It can be
49
+ reset any time later with the setter method of +SubString#attr=+.
50
+ To store an arbitrary number of pieces of information, a Hash instance
51
+ would be convenient.
52
+
46
53
  As an example, the child class {SubString}[http://rubygems.org/gems/sub_string] (provided as a different Gem)
47
54
  works as:
48
55
 
@@ -61,13 +68,16 @@ as the instance is alive, the source object is never garbage-collected (GC).
61
68
 
62
69
  === Instance methods
63
70
 
64
- The following is the instance methods of {SubObject}[http://rubygems.org/gems/sub_object] unique to this class.
71
+ The following is the instance methods of this class that do not exist in String. All are
72
+ inherited from the parent {SubObject}[http://rubygems.org/gems/sub_object] class.
65
73
 
66
74
  +#source()+:: Returns the first argument (+source+ String) given in initialization. The returned value is dup-ped and **frozen**.
67
75
  +#pos()+:: Returns the second argument (positional index) given in initialization.
68
76
  +#subsize()+:: Returns the third argument (size) given in initialization. Equivalent to the method +#size+.
69
77
  +#pos_size()+:: Returns the two-component array of +[pos, subsize]+
70
78
  +#to_source()+:: Returns the instance projected with +to_src+
79
+ +#attr=()+:: Setter of the user-defined instance variable.
80
+ +#attr()+:: Getter of the user-defined instance variable. The default is nil.
71
81
 
72
82
  In addition, +#inspect+ is redefined.
73
83
 
@@ -91,6 +101,11 @@ program applied to a huge text document with a complex grammar may
91
101
  hold a number of such String variables. By using this class instead
92
102
  of String, it can save some valuable memory.
93
103
 
104
+ Note this class also offers a function to associate an arbitrary
105
+ object with it with the setter and getter methods of +SubString#attr=+ and +SubString#attr+
106
+ (which are inherited methods from the parent class {SubObject}[http://rubygems.org/gems/sub_object]
107
+ like the others).
108
+
94
109
  === Warning about destructive methods to this instance or worse, to the source
95
110
 
96
111
  If the source object has been destructively altered, such as with the
@@ -138,8 +153,8 @@ However if you want to suppress the warning message, set the Ruby
138
153
  global variable +$VERBOSE+ to nil. Alternatively, you can control it with
139
154
  a class instance variable as
140
155
 
141
- SubObject.verbose # => getter
142
- SubObject.verbose=true # => setter
156
+ SubString.verbose # => getter
157
+ SubString.verbose=true # => setter
143
158
 
144
159
  If it is set either TRUE or FALSE, this verbosity level has a
145
160
  priority, regardless of the value of +$VERBOSE+.
@@ -149,7 +164,7 @@ In default it is nil and $VERBOSE is referred to.
149
164
  == Install
150
165
 
151
166
  This script requires {Ruby}[http://www.ruby-lang.org] Version 2.0
152
- or above. And this library depends on {SubObject (sub_object)}[https://rubygems.org/gems/sub_object], which you can
167
+ or above. Also, all this library depends on {SubObject (sub_object)}[https://rubygems.org/gems/sub_object], which you can
153
168
  find in RubyGems.
154
169
 
155
170
  You can install the packages of both this library and SubObject with the usual Ruby gem command.
@@ -5,7 +5,7 @@ require 'date'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'sub_string'.sub(/.*/){|c| (c == File.basename(Dir.pwd)) ? c : raise("ERROR: s.name=(#{c}) in gemspec seems wrong!")}
8
- s.version = "1.0.2".sub(/.*/){|c| fs = Dir.glob('changelog{,.*}', File::FNM_CASEFOLD); raise('More than one ChangeLog exist!') if fs.size > 1; warn("WARNING: Version(s.version=#{c}) already exists in #{fs[0]} - ok?") if fs.size == 1 && !IO.readlines(fs[0]).grep(/^\(Version: #{Regexp.quote c}\)$/).empty? ; c } # n.b., In macOS, changelog and ChangeLog are identical in default.
8
+ s.version = "1.1".sub(/.*/){|c| fs = Dir.glob('changelog{,.*}', File::FNM_CASEFOLD); raise('More than one ChangeLog exist!') if fs.size > 1; warn("WARNING: Version(s.version=#{c}) already exists in #{fs[0]} - ok?") if fs.size == 1 && !IO.readlines(fs[0]).grep(/^\(Version: #{Regexp.quote c}\)$/).empty? ; c } # n.b., In macOS, changelog and ChangeLog are identical in default.
9
9
  # s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
10
  # s.bindir = 'bin'
11
11
  # %w(sub_string).each do |f|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  # File.executable?(path) ? s.executables << f : raise("ERROR: Executable (#{path}) is not executable!")
14
14
  # end
15
15
  s.authors = ["Masa Sakano"]
16
- s.date = %q{2019-11-07}.sub(/.*/){|c| (Date.parse(c) == Date.today) ? c : raise("ERROR: s.date=(#{c}) is not today!")}
16
+ s.date = %q{2019-11-09}.sub(/.*/){|c| (Date.parse(c) == Date.today) ? c : raise("ERROR: s.date=(#{c}) is not today!")}
17
17
  s.summary = %q{Duck-typed String class with negligible memory use}
18
18
  s.description = <<-EOF
19
19
  Class SubString that expresses Ruby sub-String but taking up negligible memory space, as its instance holds the positional information only. It behaves exactly like String (duck-typing), except destructive modification is prohibited. If the original string is destructively altered, warning is issued.
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  }
38
38
  s.files.reject! { |fn| File.symlink? fn }
39
39
 
40
- s.add_runtime_dependency 'sub_object', '>= 1.0'
40
+ s.add_runtime_dependency 'sub_object', '>= 1.1'
41
41
  # s.add_development_dependency "bourne", [">= 0"] # '~> 2.0' to mean for only 2.0.x
42
42
  s.homepage = "https://www.wisebabel.com"
43
43
  s.rdoc_options = ["--charset=UTF-8"] # "-e UTF-8" is now Default...
@@ -106,6 +106,17 @@ class TestUnitSubString < MiniTest::Test
106
106
  assert_equal '..."'+"\n", err[-5..-1]
107
107
  assert_equal 60, (err.split(']')[-1].size-4)/10.0.round*10
108
108
  assert_equal 120, siz
109
+
110
+ # Tests of attr
111
+ assert_nil obj.attr
112
+ str = 'abcdefghijklm'*20
113
+ obj = SubString.new str, 0, 120, attr: 5
114
+ assert_equal 5, obj.attr
115
+ hs = Hash[{ try: 67 }]
116
+ obj.attr = hs
117
+ assert_equal hs, obj.attr
118
+ obj.attr[:try] = 89
119
+ assert_equal 89, obj.attr[:try]
109
120
  end
110
121
 
111
122
  # As in README.en.rdoc
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sub_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masa Sakano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2019-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sub_object
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '1.1'
27
27
  description: " Class SubString that expresses Ruby sub-String but taking up negligible
28
28
  memory space, as its instance holds the positional information only. It behaves
29
29
  exactly like String (duck-typing), except destructive modification is prohibited.