tzispa_utils 0.1.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d08b7c57f37a2f9049fda1466294f017c422e374
4
+ data.tar.gz: cd6051bd1b9a7645e380ec90d4571ffe506171be
5
+ SHA512:
6
+ metadata.gz: d459f8991295fef18a282e0622c85326a458a98b840bbf8c23ee26413c5760e286c7400b2f1fee314cd7bdd1c66d81953aa9a1dcd5e2bac3f6497c09dcfd0c5c
7
+ data.tar.gz: f880a3e225b053df40167dcd9db60bbdd489d4ccf3fd8ab2eb7efd18e69c9da976cb1020a8b2d366250bbfd94790241c4a5fbcec3473a981f9627f411b477750
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ Tzispa Utils
2
+
3
+ ## v0.1.4
4
+ - Added CSVFixer utility class
5
+
6
+ ## v0.1.3
7
+ - Fixes in String methods camelize and underscore
8
+
9
+ ## v0.1.2
10
+ - Added alias TzString for Tzispa::Utils::String
11
+
12
+ ## v0.1.1
13
+ - Added Tzispa::Utils::String
14
+ - Moved Decorator class from Tzispa main gem
15
+
16
+ ## v0.1.0
17
+ - Initial release: code split from tzispa main gem
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ Tzispa Utils
2
+
3
+ Helper utilities for Tzispa framework
@@ -0,0 +1,13 @@
1
+ module Tzispa
2
+ module Utility
3
+
4
+ require 'tzispa/utils/version'
5
+ require 'tzispa/utils/csv_fixer'
6
+ require 'tzispa/utils/decorator'
7
+ require 'tzispa/utils/lax'
8
+ require 'tzispa/utils/string'
9
+
10
+
11
+
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module Tzispa
2
+ module Utils
3
+
4
+ class CsvFixer < File
5
+
6
+ def initialize(filename, mode, separator)
7
+ @separator = separator
8
+ super(filename, mode)
9
+ end
10
+
11
+ def gets(sep, limit=nil)
12
+ line = limit ? super(sep) : super(sep, limit)
13
+ line&.split(@separator)&.map { |field|
14
+ field = field.strip
15
+ if /\A\".*\"\Z/ =~ field
16
+ "\"#{field.gsub(/\A\"(.*)\"\Z/, '\1').gsub(/([^\"])\"([^\"])/,'\1""\2')}\""
17
+ else
18
+ "\"#{field.gsub(/([^\"])\"([^\"])/, '\1""\2')}\""
19
+ end
20
+ }&.join(@separator)
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ module Tzispa
2
+ module Utils
3
+
4
+ class Decorator < SimpleDelegator
5
+
6
+ def component
7
+ @component ||= __getobj__
8
+ end
9
+
10
+ def cclass
11
+ component.class
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,42 @@
1
+ module Enumerable
2
+ def lax
3
+ Lax.new(self)
4
+ end
5
+ end
6
+
7
+ class Lax < Enumerator
8
+
9
+ def initialize(receiver)
10
+ super() do |yielder|
11
+ begin
12
+ receiver.each do |val|
13
+ if block_given?
14
+ yield(yielder, val)
15
+ else
16
+ yielder << val
17
+ end
18
+ end
19
+ rescue StopIteration
20
+ end
21
+ end
22
+ end
23
+
24
+ def map(&block)
25
+ Lax.new(self) do |yielder, val|
26
+ yielder << block.call(val)
27
+ end
28
+ end
29
+
30
+ def take(n)
31
+ taken = 0
32
+ Lax.new(self) do |yielder, val|
33
+ if taken < n
34
+ yielder << val
35
+ taken += 1
36
+ else
37
+ raise StopIteration
38
+ end
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tzispa
4
+ module Utils
5
+
6
+ class String
7
+
8
+ NAMESPACE_SEPARATOR = '::'
9
+ CLASSIFY_SEPARATOR = '_'
10
+ UNDERSCORE_SEPARATOR = '/'
11
+
12
+ UNDERSCORE_DIVISION_TARGET = '\1_\2'
13
+
14
+ def initialize(str)
15
+ @string = str.to_s
16
+ end
17
+
18
+ def to_s
19
+ @string
20
+ end
21
+
22
+ def ==(other)
23
+ to_s == other
24
+ end
25
+
26
+ def self.constantize(str)
27
+ self.new(str).constantize
28
+ end
29
+
30
+ def constantize
31
+ names = @string.split(NAMESPACE_SEPARATOR)
32
+ names.shift if names.empty? || names.first.empty?
33
+ constant = Object
34
+ names.each do |name|
35
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
36
+ end
37
+ constant
38
+ end
39
+
40
+ def self.camelize(str)
41
+ self.new(str).camelize
42
+ end
43
+
44
+ def camelize
45
+ self.class.new( @string.split(CLASSIFY_SEPARATOR).collect{ |w| w.capitalize }.join)
46
+ end
47
+
48
+ def camelize!
49
+ @string = @string.split(CLASSIFY_SEPARATOR).collect!{ |w| w.capitalize }.join
50
+ end
51
+
52
+ def self.underscore(str)
53
+ self.new(str).underscore
54
+ end
55
+
56
+ def underscore
57
+ self.class.new(@string.dup.tap { |s|
58
+ s.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
59
+ s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
60
+ s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
61
+ s.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
62
+ s.downcase!
63
+ })
64
+ end
65
+
66
+ def underscore!
67
+ @string = @string.tap { |s|
68
+ s.gsub!(NAMESPACE_SEPARATOR, UNDERSCORE_SEPARATOR)
69
+ s.gsub!(/([A-Z\d]+)([A-Z][a-z])/, UNDERSCORE_DIVISION_TARGET)
70
+ s.gsub!(/([a-z\d])([A-Z])/, UNDERSCORE_DIVISION_TARGET)
71
+ s.gsub!(/[[:space:]]|\-/, UNDERSCORE_DIVISION_TARGET)
72
+ s.downcase!
73
+ }
74
+ end
75
+
76
+ private
77
+
78
+ def gsub(pattern, replacement = nil, &blk)
79
+ if block_given?
80
+ @string.gsub(pattern, &blk)
81
+ else
82
+ @string.gsub(pattern, replacement)
83
+ end
84
+ end
85
+
86
+
87
+ end
88
+ end
89
+ end
90
+
91
+ TzString = Tzispa::Utils::String
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tzispa
4
+ module Utils
5
+
6
+ VERSION = '0.1.4'
7
+ NAME = 'Tzispa Utils'
8
+ GEM_NAME = 'tzispa_utils'
9
+
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Tzispa
2
+ module Utility
3
+
4
+ require 'tzispa/utils'
5
+
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tzispa_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Juan Antonio Piñero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Utilities for Tzispa
14
+ email:
15
+ - japinero@area-integral.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - README.md
22
+ - lib/tzispa/utils.rb
23
+ - lib/tzispa/utils/csv_fixer.rb
24
+ - lib/tzispa/utils/decorator.rb
25
+ - lib/tzispa/utils/lax.rb
26
+ - lib/tzispa/utils/string.rb
27
+ - lib/tzispa/utils/version.rb
28
+ - lib/tzispa_utils.rb
29
+ homepage: https://www.area-integral.com
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.5.1
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Utilities for Tzispa
53
+ test_files: []