str2time 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in str2time.gemspec
4
+ gemspec
@@ -0,0 +1,11 @@
1
+ Str2time
2
+ ========
3
+
4
+ Str2time is a minimal utility to convert a string representation of time into a
5
+ certain amount of seconds. It is intended to use when you need to input a time
6
+ lapse in a human way, as string.
7
+
8
+ It can convert the following formats:
9
+
10
+ "1:30" => 5400
11
+ "1h 30m" => 5400
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the puret plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
@@ -0,0 +1,11 @@
1
+ module Str2time
2
+ def self.convert(str)
3
+ regexps = [/^(\d+):([0-5]?[0-9])$/, /(\d+)h ?([0-5]?[0-9])m/]
4
+
5
+ if regexps.detect{|x| str =~ x}
6
+ $1.to_i*3600 + $2.to_i*60
7
+ else
8
+ nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Str2time
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "str2time/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "str2time"
7
+ s.version = Str2time::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Roger Campos"]
10
+ s.email = ["roger@itnig.net"]
11
+ s.homepage = "https://github.com/rogercampos/str2time"
12
+ s.summary = %q{Convert string time representations into seconds}
13
+ s.description = %q{Convert string time representations into seconds}
14
+
15
+ s.rubyforge_project = "str2time"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+ require 'str2time'
3
+
4
+ class Str2timeTest < Test::Unit::TestCase
5
+ def test_convert_colon_format
6
+ assert_equal 5400, Str2time.convert("1:30")
7
+ end
8
+
9
+ def test_convert_humanized_format
10
+ assert_equal 5400, Str2time.convert("1h 30m")
11
+ end
12
+
13
+ def test_one_number_minutes
14
+ assert_equal 3660, Str2time.convert("1:1")
15
+ end
16
+
17
+ def test_nonsense_minutes
18
+ assert_equal nil, Str2time.convert("1h 70m")
19
+ end
20
+
21
+ def test_non_numerical_inputs
22
+ assert_equal nil, Str2time.convert("5:3a")
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ require 'test/unit'
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: str2time
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Roger Campos
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-26 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Convert string time representations into seconds
23
+ email:
24
+ - roger@itnig.net
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/str2time.rb
37
+ - lib/str2time/version.rb
38
+ - str2time.gemspec
39
+ - test/str2time_test.rb
40
+ - test/test_helper.rb
41
+ has_rdoc: true
42
+ homepage: https://github.com/rogercampos/str2time
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: str2time
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Convert string time representations into seconds
75
+ test_files: []
76
+