hellobase 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hellobase/array_access.rb +26 -0
- data/lib/hellobase/string_access.rb +26 -0
- data/lib/hellobase/version.rb +1 -1
- data/lib/hellobase.rb +2 -1
- metadata +3 -2
- data/lib/hellobase/array_index.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f9ca937930f71388e8a138668e51b733ff4c7936cfe9426d0537644466ce235
|
4
|
+
data.tar.gz: 3801d7247a328ef35175d102247a035e6ba5eeb3d25d89e901b066abe6b8b040
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f607d4f547e991197c938a653eb0b08d3f3e0cb0a746f5a307a7369b75fd7d7a7b10181e508b36f0d93ed1f159ccb6122c84d825537a034dfae4d84c67849407
|
7
|
+
data.tar.gz: ad15c1ea31b58a10747f0e42f878dbafb5608d4be9dfba33209501ecc5fc961da9a80d2b69ef86f8ba15b116e64b55011b8ad12a517f5fbd95a34bd2eb242fbe
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Array
|
2
|
+
def hb_elem(hb_index)
|
3
|
+
raise Hellobase::Error.new(:array_index, self, hb_index) unless index = hb_convert_index(hb_index)
|
4
|
+
|
5
|
+
self[index]
|
6
|
+
end
|
7
|
+
|
8
|
+
def hb_elem_range(hb_start_index, hb_end_index)
|
9
|
+
unless (start_index = hb_convert_index(hb_start_index)) && (end_index = hb_convert_index(hb_end_index)) && (end_index >= start_index)
|
10
|
+
raise Hellobase::Error.new(:array_index, self, hb_start_index, hb_end_index)
|
11
|
+
end
|
12
|
+
|
13
|
+
self[start_index..end_index]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def hb_convert_index(hb_index)
|
19
|
+
return nil if hb_index == 0
|
20
|
+
|
21
|
+
index = hb_index > 0 ? hb_index - 1 : length + hb_index
|
22
|
+
return nil if index < 0 || index > length - 1
|
23
|
+
|
24
|
+
index
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class String
|
2
|
+
def hb_char(hb_index)
|
3
|
+
raise Hellobase::Error.new(:string_index, self, hb_index) unless index = hb_convert_index(hb_index)
|
4
|
+
|
5
|
+
self[index]
|
6
|
+
end
|
7
|
+
|
8
|
+
def hb_char_range(hb_start_index, hb_end_index)
|
9
|
+
unless (start_index = hb_convert_index(hb_start_index)) && (end_index = hb_convert_index(hb_end_index)) && (end_index >= start_index)
|
10
|
+
raise Hellobase::Error.new(:string_index, self, hb_start_index, hb_end_index)
|
11
|
+
end
|
12
|
+
|
13
|
+
self[start_index..end_index]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def hb_convert_index(hb_index)
|
19
|
+
return nil if hb_index == 0
|
20
|
+
|
21
|
+
index = hb_index > 0 ? hb_index - 1 : length + hb_index
|
22
|
+
return nil if index < 0 || index > length - 1
|
23
|
+
|
24
|
+
index
|
25
|
+
end
|
26
|
+
end
|
data/lib/hellobase/version.rb
CHANGED
data/lib/hellobase.rb
CHANGED
@@ -5,10 +5,11 @@ require 'active_support/core_ext/date_time'
|
|
5
5
|
require 'active_support/duration'
|
6
6
|
require 'tod'
|
7
7
|
|
8
|
-
require 'hellobase/
|
8
|
+
require 'hellobase/array_access'
|
9
9
|
require 'hellobase/date_creation'
|
10
10
|
require 'hellobase/datetime_creation'
|
11
11
|
require 'hellobase/divide_by_zero'
|
12
|
+
require 'hellobase/string_access'
|
12
13
|
require 'hellobase/time_creation'
|
13
14
|
|
14
15
|
module Hellobase
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hellobase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Wang
|
@@ -81,10 +81,11 @@ extra_rdoc_files: []
|
|
81
81
|
files:
|
82
82
|
- MIT-LICENSE
|
83
83
|
- lib/hellobase.rb
|
84
|
-
- lib/hellobase/
|
84
|
+
- lib/hellobase/array_access.rb
|
85
85
|
- lib/hellobase/date_creation.rb
|
86
86
|
- lib/hellobase/datetime_creation.rb
|
87
87
|
- lib/hellobase/divide_by_zero.rb
|
88
|
+
- lib/hellobase/string_access.rb
|
88
89
|
- lib/hellobase/time_creation.rb
|
89
90
|
- lib/hellobase/version.rb
|
90
91
|
homepage:
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class Array
|
2
|
-
def hb_elem(hb_index)
|
3
|
-
raise Hellobase::Error.new(:array_index, self, hb_index) if hb_index == 0
|
4
|
-
index = hb_index > 0 ? hb_index - 1 : hb_index
|
5
|
-
|
6
|
-
raise Hellobase::Error.new(:array_index, self, hb_index) if (index >= 0 && index > length - 1) || (index < 0 && (-1 * index > length))
|
7
|
-
self[index]
|
8
|
-
end
|
9
|
-
end
|