utilities 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/utilities.rb +40 -1
  2. data/lib/version.rb +1 -1
  3. metadata +6 -6
data/lib/utilities.rb CHANGED
@@ -48,9 +48,24 @@ class String
48
48
  def to_time
49
49
  Time.parse(self)
50
50
  end
51
+
52
+ # Transform self to a float representation of a time (HH:MM)
53
+ # Ex: "14:30" => 14.5, "12h00" => 12.0
54
+ def hour_to_float
55
+ hour, min = split(/:|h/)
56
+ hour.to_f + min.to_f / 60.0
57
+ end
51
58
  end
52
59
 
53
60
  class Numeric
61
+ # Transform self to a string formatted time (HH:MM)
62
+ # Ex: 14.5 => "14:30"
63
+ def hour_to_string delimiter = ':'
64
+ hour = self.to_i
65
+ min = "%02d" % (self.abs * 60 % 60).to_i
66
+ "#{hour}#{delimiter}#{min}"
67
+ end
68
+
54
69
  # Convert to degrees
55
70
  def degrees
56
71
  self * Math::PI / 180
@@ -84,7 +99,31 @@ class Numeric
84
99
  alias_method :percent_of, :percentage_of
85
100
  end
86
101
 
87
- module Utilities
102
+ module Utilities
103
+ module Subclasses
104
+ # Find every subclass of an object
105
+ def subclasses(direct = false)
106
+ classes = []
107
+ if direct
108
+ ObjectSpace.each_object(Class) do |c|
109
+ classes << c if c.superclass == self
110
+ end
111
+ else
112
+ ObjectSpace.each_object(Class) do |c|
113
+ classes << c if c.ancestors.include?(self) and (c != self)
114
+ end
115
+ end
116
+ classes
117
+ end
118
+ end
119
+
120
+ module Submodules
121
+ # Find every submodules of an object
122
+ def submodules
123
+ constants.collect{ |const_name| const_get(const_name) }.select{ |const| const.class == Module }
124
+ end
125
+ end
126
+
88
127
  module Statistics
89
128
  # Add each object of the array to each other in order to get the sum, as long as all objects respond to + operator
90
129
  def sum
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Utilities
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- BUILD = 7
4
+ BUILD = 8
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{BUILD}"
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utilities
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Blais
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-02-25 00:00:00 -05:00
20
+ date: 2011-04-26 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies: []
23
23
 
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements: []
68
68
 
69
69
  rubyforge_project:
70
- rubygems_version: 1.3.7
70
+ rubygems_version: 1.5.0
71
71
  signing_key:
72
72
  specification_version: 3
73
73
  summary: Few utilities include in all my projects