scoppie 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3c3decb5df0a490f569339dc29dc39d09a549ff
4
+ data.tar.gz: 4ba0a2d09bf589e56778bc085dbeaf6e09c9515c
5
+ SHA512:
6
+ metadata.gz: 9abbb8ef8bbcda135f2a6e24972ef549ca561bd55f04fd007ae8e74cbc48165f91837619a74978c4791bb53586f41a6800dca1be48b3722ae8f61433399d1c1f
7
+ data.tar.gz: 546f7f84e5075163bcaf1c531e1f0efd3e01146fb9d338adeebc39d30d30766dfb4b1228fa3d31361daee462431cb15d164b191251658aaa791f567f17af1506
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # scopy
data/lib/scope.rb ADDED
@@ -0,0 +1,13 @@
1
+ require_relative 'scope_methods'
2
+
3
+ class Scope
4
+ include ScopeMethods
5
+ extend ScopeMethods
6
+
7
+ attr_reader :value, :short_value
8
+
9
+ def initialize value
10
+ fail "Invalid Scope (#{value})" unless Scope.valid? value
11
+ @value = value
12
+ end
13
+ end
@@ -0,0 +1,94 @@
1
+ require 'date'
2
+
3
+ module ScopeMethods
4
+ include Comparable
5
+
6
+ module ClassMethods
7
+
8
+ def make_scope ayear, amonth
9
+ scope_string = Scope.build_scope_string ayear, amonth
10
+ Scope.new scope_string
11
+ end
12
+
13
+ def build_scope_string ayear, amonth
14
+ amonth = amonth.to_i
15
+ ayear = ayear.to_i
16
+ raise "Invalid Scope string #{ayear} #{amonth}" unless valid_month?(amonth) and valid_year?(ayear)
17
+ amonth < 10 ? "#{ayear}0#{amonth.to_i}" : "#{ayear}#{amonth.to_i}"
18
+ end
19
+
20
+ def valid? scope
21
+ valid_month?(month(scope)) and valid_year?(year(scope))
22
+ end
23
+
24
+ def year scope
25
+ scope[0..3].to_i
26
+ end
27
+
28
+ def month scope
29
+ scope[-2, 2].to_i
30
+ end
31
+
32
+ def date_to_scope date
33
+ Scope.new(build_scope_string date.year, date.month)
34
+ end
35
+
36
+ def scope_to_date scope
37
+ Date.new(year(scope), month(scope))
38
+ end
39
+
40
+ private
41
+ def valid_month? month_in_number
42
+ month_in_number.between? 1, 12
43
+ end
44
+
45
+ def valid_year? year_in_number
46
+ year_in_number.between? 1900, 3000
47
+ end
48
+ end
49
+
50
+ module IntanceMethods
51
+ def valid?
52
+ Scope.valid? @value
53
+ end
54
+
55
+ def to_s
56
+ @value
57
+ end
58
+
59
+ def year
60
+ Scope.year @value
61
+ end
62
+
63
+ def month
64
+ Scope.month @value
65
+ end
66
+
67
+ def prior
68
+ date = Scope.scope_to_date(@value).prev_month
69
+ Scope.date_to_scope date
70
+ end
71
+
72
+ def next
73
+ date = Scope.scope_to_date(@value).next_month
74
+ Scope.date_to_scope date
75
+ end
76
+
77
+ def to_i
78
+ @value.to_i
79
+ end
80
+
81
+ def to_date
82
+ Scope.scope_to_date @value
83
+ end
84
+
85
+ def <=>(other)
86
+ to_date <=> other.to_date
87
+ end
88
+ end
89
+
90
+ def self.included receiver
91
+ receiver.extend ClassMethods
92
+ receiver.send :include, IntanceMethods
93
+ end
94
+ end
data/lib/scoppie.rb ADDED
@@ -0,0 +1 @@
1
+ require 'scope'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scoppie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gedean Dias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Scope handler
14
+ email: gedean.dias@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/scope.rb
21
+ - lib/scope_methods.rb
22
+ - lib/scoppie.rb
23
+ homepage: https://github.com/gedean/scoppie
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Scope Handler
47
+ test_files: []