supplement 2.5.2 → 2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79a21e0dbd2675a47d89f622fc088531dfb9cbb0ff2a9cf233ba374e1fda29f4
4
- data.tar.gz: 42b89d17996c6466a6fe018cba078c021befd3f6c63b06778254b545ac8f69db
3
+ metadata.gz: 9754618686c48891d7ca99a09508ce3df98c97ed7543ec1439422f1b8e744de9
4
+ data.tar.gz: 04d319813eca8255a920d8d4d0a711cd0de91f28360f2df3b3da7713c59b770e
5
5
  SHA512:
6
- metadata.gz: b3418f116fba332053b8c8832f3470abac8a739807c798051e7f07471964bdaadc9f8d863b19613f46371f9ec5830bbd01be62fa542a71be6342a4739075793d
7
- data.tar.gz: 9cabe357965f30a5aa0a16bf412cf7506a7f3ac87772f716a07348cb6588203e05330167e9236055102b59b8d3a4320b67260079812f1e2a6eaf153d1d29e4f3
6
+ metadata.gz: 73c88f02010a6dde56e25d492782b861015cb1ccadb22483e5100a5ece3b1c6d0a80ce405b3e3ff67c9f75da14b9c1e08c92a9d5e24118dd4a09fa81b22556d3
7
+ data.tar.gz: 433665cf2b86261adee2240c49301e1b2f06ced977d3d1275f085e0ed11d8558f3f9bf40d1d5642e623a6caf4f747377070b23d1a611796e036c15f8c0540b76
data/LICENSE CHANGED
@@ -5,7 +5,7 @@
5
5
  |___/\__,_| .__/| .__/|_|\___|_| |_| |_|\___|_| |_|\__|
6
6
  |_| |_|
7
7
 
8
- Copyright (C) 2009-2019, Bertram Scharpf <software@bertram-scharpf.de>.
8
+ Copyright (C) 2009-2020, Bertram Scharpf <software@bertram-scharpf.de>.
9
9
  All rights reserved.
10
10
 
11
11
  Redistribution and use in source and binary forms, with or without
data/README CHANGED
@@ -1,12 +1,26 @@
1
- = supplement 2.5.2 -- Useful Ruby enhancements
1
+ = supplement 2.6 -- Useful Ruby enhancements
2
+
2
3
 
3
4
  Some simple Ruby extensions.
4
5
 
6
+
7
+ == Author
8
+
9
+ Bertram Scharpf <software@bertram-scharpf.de>
10
+
11
+
12
+ == Motivation
13
+
14
+ The original motivation was my conviction that a language that has a
15
+ Numeric#nonzero? method induces a programming style that as well demands
16
+ for a String#notempty? method.
17
+
18
+
19
+
5
20
  == Description
6
21
 
7
22
  These are methods on standard classes that didn't manage to become part of
8
- the Ruby interpreter. (Although, some are part of Ruby 1.9/1.8.7 but not
9
- 1.8.6).
23
+ the Ruby interpreter. (Although, some did in the meantime.)
10
24
 
11
25
  They are all very small, most of them have less than 15 lines of code.
12
26
  So they would not be a weight in the Ruby interpreter but it is very
@@ -18,6 +32,8 @@ to make them part of their programming style.
18
32
  If you like to get taunted, then go to the Ruby mailing list and propose
19
33
  one of them to be included into the Ruby standard.
20
34
 
35
+
36
+
21
37
  == Intention
22
38
 
23
39
  In my own code I use quite often a method <code>String#notempty?</code>
@@ -27,20 +43,27 @@ the discussion evolves the same every time.
27
43
 
28
44
  Now here it is where I can just point to.
29
45
 
46
+
47
+
30
48
  == Contents (uncomplete)
31
49
 
32
- * String#notempty?
33
- * String#clear
34
- * String#head
35
- * String#tail
36
- * String#rest
37
- * String#start_with?
38
- * String#end_with?
39
- * Array#notempty?
40
- * Hash#notempty?
41
- * Struct.[]
42
- * Process.renice
43
- * Interval timer
44
- * File system stats
45
- * LockedFile
50
+ * String#notempty?
51
+ * String#clear
52
+ * String#head
53
+ * String#tail
54
+ * String#rest
55
+ * String#start_with?
56
+ * String#end_with?
57
+ * Array#notempty?
58
+ * Hash#notempty?
59
+ * Struct.[]
60
+ * Integer.roman
61
+ * Date.easter
62
+ * File system stats
63
+ * Process.renice
64
+ * Interval timer
65
+ * LockedFile
66
+
67
+
46
68
 
69
+ // vim:set ft=asciidoc :
@@ -4,6 +4,7 @@
4
4
 
5
5
  require "date"
6
6
 
7
+
7
8
  class Date
8
9
 
9
10
  def y ; year ; end
@@ -12,8 +13,38 @@ class Date
12
13
 
13
14
  def to_a ; [ year, month, day ] ; end
14
15
 
16
+
17
+ EASTER = "Easter"
18
+
19
+ class <<self
20
+
21
+ def easter_western year
22
+ # This is after Donald E. Knuth and it works for both
23
+ # Julian (1582 and before) and Gregorian (1583 and after) calendars.
24
+ g = year%19 + 1 # golden number
25
+ c = year/100 + 1 # century
26
+ x = (3*c/4) - 12 # corrections
27
+ z = (8*c+5)/25 - 5
28
+ d = 5*year/4 - x - 10 # March((-d)%7)th is Sunday
29
+ e = (11*g + 20 + z - x) % 30 # moon phase
30
+ e += 1 if e == 25 and g > 11 or e == 24
31
+ n = 44 - e # full moon
32
+ n += 30 if n < 21
33
+ month = 3
34
+ day = n+7 - (d+n)%7
35
+ if day > 31 then
36
+ month += 1
37
+ day -= 31
38
+ end
39
+ civil year, month, day
40
+ end
41
+ alias easter easter_western
42
+
43
+ end
44
+
15
45
  end
16
46
 
47
+
17
48
  unless DateTime.method_defined? :to_time then
18
49
 
19
50
  class Time
@@ -39,7 +70,7 @@ unless DateTime.method_defined? :to_time then
39
70
  def to_datetime ; DateTime.new! Date.jd_to_ajd(jd,0,0), @of, @sg ; end
40
71
  end
41
72
 
42
- class DateTime < Date
73
+ class DateTime
43
74
  def to_time
44
75
  (new_offset 0).instance_eval do
45
76
  Time.utc year, mon, mday, hour, min, sec + sec_fraction
@@ -0,0 +1,44 @@
1
+ #
2
+ # roman.rb -- Roman numerals
3
+ #
4
+
5
+ class Integer
6
+
7
+ ROMANS = {
8
+ 1 => 'I',
9
+ 5 => 'V',
10
+ 10 => 'X',
11
+ 50 => 'L',
12
+ 100 => 'C',
13
+ 500 => 'D',
14
+ 1000 => 'M'
15
+ }
16
+ ROMANSUB = [
17
+ [1000, 100],
18
+ [ 500, 100],
19
+ [ 100, 10],
20
+ [ 50, 10],
21
+ [ 10, 1],
22
+ [ 5, 1],
23
+ [ 1, 0]
24
+ ]
25
+
26
+ # :call-seq:
27
+ # int.roman() -> str or nil
28
+ #
29
+ # Return the roman numeral as uppercase if possible.
30
+ #
31
+ # 1994.roman #=> "MCMXCIV"
32
+ # -1.roman #=> nil
33
+ #
34
+ def roman
35
+ return ROMANS[ self] if ROMANS.has_key? self
36
+ ROMANSUB.each do |cut,sub|
37
+ return cut.roman + (self - cut).roman if self > cut
38
+ return sub.roman + (self + sub).roman if self >= cut - sub and self < cut
39
+ end
40
+ nil
41
+ end
42
+
43
+ end
44
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supplement
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: '2.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-31 00:00:00.000000000 Z
11
+ date: 2020-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: autorake
@@ -52,6 +52,7 @@ files:
52
52
  - lib/supplement/itimer.h
53
53
  - lib/supplement/locked.c
54
54
  - lib/supplement/locked.h
55
+ - lib/supplement/roman.rb
55
56
  - lib/supplement/terminal.c
56
57
  - lib/supplement/terminal.h
57
58
  homepage: http://www.bertram-scharpf.de/software/supplement