wobbly 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/wobbly +10 -0
  3. data/lib/wobbly.rb +41 -0
  4. metadata +87 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a517cc5f47725aa85ae95468cac68b0797b5bc75
4
+ data.tar.gz: 7deee7b89d829ca27b267bf9929e4d779bcb2e42
5
+ SHA512:
6
+ metadata.gz: 4e4b733f162d1d1a79bc4fab4338a5c7cc7cac79236b2ed7ae2ad0ffe1ac9cc2f3ba72615d1c1d260baa0a959e8579bfd830961483fa72669a0320d0b88e371f
7
+ data.tar.gz: edd6b0ab0b1373625317342e798799b5822f82edf9be17244a7707e9bc340ec17104e728a12a6ae793caecae17ddac4aeea55a8f56cfa632a4883d1d718b9aee
data/bin/wobbly ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require File.expand_path('../lib/wobbly', File.dirname(__FILE__))
5
+
6
+ if !ARGV.empty?
7
+ puts Wobbly.in(ARGV[0])
8
+ else
9
+ puts "Usage: wobbly 1h2m"
10
+ end
data/lib/wobbly.rb ADDED
@@ -0,0 +1,41 @@
1
+ module Wobbly
2
+ # Parse the string into chunks
3
+ def self.tokens(s)
4
+ s.scan(/[0-9]+[smhDMWY]/)
5
+ end
6
+
7
+ # Process the tokens into the collective date
8
+ def self.in(s)
9
+ now = Time.now
10
+
11
+ tokens(s).each do |t|
12
+ token = t.gsub(/(\d+)/, '\1,').split(',')
13
+
14
+ next if token.size != 2
15
+
16
+ amt = token[0].to_i
17
+ seg = token[1].to_s
18
+
19
+ case seg
20
+ when 's'
21
+ now = now + amt
22
+ when 'm'
23
+ now = now + (amt*60)
24
+ when 'h'
25
+ now = now + (amt*60*60)
26
+ when 'D'
27
+ now = now + (amt*24*60*60)
28
+ when 'W'
29
+ now = now + (amt*7*24*60*60)
30
+ when 'M'
31
+ now = now + (amt*4*7*24*60*60)
32
+ when 'Y'
33
+ now = now + (amt*12*4*7*24*60*60)
34
+ else
35
+ raise "Invalid time segment provided #{seg}"
36
+ end
37
+ end
38
+
39
+ now
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wobbly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Nieuwoudt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.7.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '5.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.7.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.4'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 10.4.2
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.4'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 10.4.2
53
+ description: Wobbly is an easy to use token type date parser in Ruby that allows you
54
+ easily parse short dates such as 1h2m
55
+ email: sean@isean.co.za
56
+ executables:
57
+ - wobbly
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - bin/wobbly
62
+ - lib/wobbly.rb
63
+ homepage: https://isean.co.za
64
+ licenses:
65
+ - GPL-3.0
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.11
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Wobbly is an easy to use token type date parser in Ruby
87
+ test_files: []