silverball 0.1.0

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: 5715cfaf8aa5a38e40b7c6acf9423d5e28dfd09e
4
+ data.tar.gz: ce44395410cdf7224d3cce4129dab4313017582b
5
+ SHA512:
6
+ metadata.gz: e1ca9825debd439087a0b78184b5385dae5c58a73b25c774cc7b202602d14327dbb0df40097404afb020ccdf8db46c46f7036b7bb7fb787755fbe04c734d7760
7
+ data.tar.gz: 1c14ba14b7ac1acac1d864be9f8c0815d2a6c689f42e0bc2eaeca56df207fa6d1a907d3bf4d4afa94617a93abca3dac700a810e663962cfe8c5f3558c8745eb5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Change log
2
+
3
+ This document represents a high-level overview of changes made to this project.
4
+ It will not list every miniscule change, but will allow you to view - at a
5
+ glance - what to expact from upgrading to a new version.
6
+
7
+ ## [unpublished]
8
+
9
+ ### Added
10
+
11
+ ### Changed
12
+
13
+ ### Fixed
14
+
15
+ ### Security
16
+
17
+ ### Deprecated
18
+
19
+ ### Removed
20
+
21
+
22
+ ## [0.1.0] - 2017-01-03
23
+
24
+ ### Added
25
+
26
+ - Function to convert timespan in seconds to human-readable words.
27
+ - Function to convert integer to string with thousands-separator
28
+ - Function to convert fraction to rounded percentage
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sunscout.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2016 Michael Senn
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # CHANGE ME
2
+
3
+ ## License
4
+
5
+ The gem is available as open source under the terms of the [Apache-2.0 License](http://opensource.org/licenses/Apache-2.0).
6
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hive-stalker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,74 @@
1
+ # coding_ utf-8
2
+
3
+ module Silverball
4
+ module DateTime
5
+ SECONDS_PER_MINUTE = 60
6
+ SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60
7
+ SECONDS_PER_DAY = SECONDS_PER_HOUR * 24
8
+
9
+ def timespan_in_words(seconds, unit: nil, round: 2)
10
+ seconds = seconds.to_f unless unit.nil?
11
+
12
+ if seconds >= SECONDS_PER_DAY && (unit.nil? || unit == :days)
13
+ days = seconds / SECONDS_PER_DAY
14
+ seconds -= days * SECONDS_PER_DAY
15
+
16
+ if unit == :days
17
+ if days == days.to_i
18
+ days = days.to_i
19
+ else
20
+ days - days.round(round)
21
+ end
22
+ end
23
+ else
24
+ days = 0
25
+ end
26
+
27
+ if seconds >= SECONDS_PER_HOUR && (unit.nil? || unit == :hours)
28
+ hours = seconds / SECONDS_PER_HOUR
29
+ seconds -= hours * SECONDS_PER_HOUR
30
+
31
+ if unit == :hours
32
+ if hours == hours.to_i
33
+ hours = hours.to_i
34
+ else
35
+ hours - hours.round(round)
36
+ end
37
+ end
38
+ else
39
+ hours = 0
40
+ end
41
+
42
+ if seconds >= SECONDS_PER_MINUTE && (unit.nil? || unit == :minutes)
43
+ minutes = seconds / SECONDS_PER_MINUTE
44
+ seconds -= minutes * SECONDS_PER_MINUTE
45
+
46
+ if unit == :minutes
47
+ if minutes == minutes.to_i
48
+ minutes = minutes.to_i
49
+ else
50
+ minutes - minutes.round(round)
51
+ end
52
+ end
53
+ else
54
+ minutes = 0
55
+ end
56
+
57
+ if unit == :seconds
58
+ if seconds == seconds.to_i
59
+ seconds = seconds.to_i
60
+ else
61
+ seconds = seconds.round(rouond)
62
+ end
63
+ end
64
+
65
+ out = []
66
+ out << "#{ days }d" if days > 0
67
+ out << "#{ hours }h" if hours > 0
68
+ out << "#{ minutes }m" if minutes > 0
69
+ out << "#{ seconds }s" if seconds > 0 || (seconds == 0 && minutes == 0 && hours == 0 && days == 0)
70
+
71
+ out.join(' ')
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ # coding_ utf-8
2
+
3
+ module Silverball
4
+ module Numbers
5
+ def number_with_separator(number, sep = "'")
6
+ number.to_s.reverse.gsub(/\d\d\d(?=\d)/) { |s| "#{ s }#{ sep }" }.reverse
7
+ end
8
+
9
+ def fraction_as_percentage(part, full, accuracy = 1)
10
+ percentage = (part * 100.0 / full).round(accuracy)
11
+
12
+ "#{ percentage }%"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ module Silverball
2
+ end
data/lib/silverball.rb ADDED
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+
3
+ require 'silverball/silverball'
4
+ require 'silverball/numbers'
5
+ require 'silverball/date_time'
6
+
7
+ module Silverball
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "silverball"
7
+ spec.version = '0.1.0'
8
+ spec.authors = ["Michael Senn"]
9
+ spec.email = ["michael@morrolan.ch"]
10
+
11
+ spec.summary = %q{Various formatting for various things}
12
+ # spec.description = %q{}
13
+ spec.homepage = "https://bitbucket.org/Lavode/silverball"
14
+ spec.license = "Apache-2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "yard"
25
+ end
26
+
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: silverball
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Senn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - michael@morrolan.ch
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CHANGELOG.md
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/silverball.rb
85
+ - lib/silverball/date_time.rb
86
+ - lib/silverball/numbers.rb
87
+ - lib/silverball/silverball.rb
88
+ - silverball.gemspec
89
+ homepage: https://bitbucket.org/Lavode/silverball
90
+ licenses:
91
+ - Apache-2.0
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Various formatting for various things
113
+ test_files: []