ruby-fizzbuzz 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 15be72f9c77aaa84d7fa6f92403623aa38d62add
4
- data.tar.gz: a7b92647afb2cf83ded7bd442829964b09a6a5e5
2
+ SHA256:
3
+ metadata.gz: fbc46615ef6b3f04b5ee9d784eaaf26db82ea1fc3e2c6d4def2f87c4ff6d9295
4
+ data.tar.gz: 937d7c799e0cd43ff6bf703014428530f41b108ad56d08b8dcb4cb29d92d736c
5
5
  SHA512:
6
- metadata.gz: ca579ce7e2c92319421613c3f9aaaddff506a222682760d52c03701d53da730d0da195eb9d30c4adbc2b4f45e7ee2ab600f9c64a12060244fe069e3595c31550
7
- data.tar.gz: ae2ba4d86ac6ba15ee7245535f5b797485aef4cee26f713fe3309db983002c0ad85e543b5589518cc2bfeabc2d3b0576f13580861abf3c28eb4d6bc1be275504
6
+ metadata.gz: 3c8d66d61187180addad7e50f4f7ef2e99b9e4b8a9ed1644923e15b3fe7613c1c8004c7cbd0c316455cb69388ffe0fea62160dcbfbf96b82c4c37280929fdffe
7
+ data.tar.gz: fc0e431a4ff78c4dd0454f065025a5fff077bdfc42004ef9e194f2d63f4f1bfb4cc0f000432f9199775ec1cd65fb82d07e728745a3a1484b4d18c574fb0732ab
@@ -0,0 +1,5 @@
1
+ ��Mdn�fvNaIhqWv���������&�.���X+"7#;5q%��Lb��WXn�1i��8�~�c���оf���*�D3�9>�D���O� Xl�0��MW��6�:�(��Ck�&4z�k�����@�m�i�@+�\A�M���a���a�ts��/�{��Ќ:,
2
+ J���������C��P�^cQO�׏"�zdN_1!Y�g��0A�>i��s�˴��ډ|�ܙ&]w����AD^�0%1
3
+ ������ƭ�y�� ^��O������a=�I6���
4
+ ��u9�֊�@s딞+3����[֭�]�@�
5
+ �9f�B1�$�<��1�g�����y0���H�LT"h�����p�g_����W���"o3���(.�(�W�
Binary file
data/AUTHORS CHANGED
@@ -1 +1 @@
1
- Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
1
+ Krzysztof Wilczyński <kw@linux.com> (@kwilczynski)
@@ -0,0 +1,175 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.8.0] - 2020-02-05
11
+ ### Added
12
+
13
+ - Added new `step` singleton method to the _FizzBuzz_ class.
14
+ - Added **Code of Conduct** to the project.
15
+ - Added new `--line` command line switch to the `fizzbuzz` script, which allows for printing values in a single line.
16
+ - Added support for the _Integer Unification_ in Ruby version **2.4** onwards.
17
+ - Added few optimisations e.g., `LIKELY` and `UNLIKELY` macros, and improved the `INTEGER_P` macro.
18
+ - Added support for installing and building on _Windows_ has been confirmed with an environment set by _Ruby Installer_
19
+ and _DevKit_ (which is _MinGW_ under the hood).
20
+ - Added more `CFLAGS` to `extconf.rb` file.
21
+ - Added definition of `_DEFAULT_SOURCE` since `_BSD_SOURCE` and `_SVID_SOURCE` are deprecated.
22
+ - Added friendly error message when the `ruby-fizzbuzz` Ruby gem is missing.
23
+ - Added `.editorconfig` file for Ruby.
24
+ - Added very basic `.gitattributes` file.
25
+ - Added `.mailmap` file to be used by Git.
26
+ - Added NOTICE file to the project.
27
+
28
+ ### Changed
29
+
30
+ - Moved to _Ubuntu Xenial_ on _Travis CI_.
31
+ - Re-factored _Array_ class integration.
32
+ - Re-factored custom `typedef` types and some other small changes.
33
+ - Replaced `File.exists?` with `File.exist?`.
34
+ - Replaced usage of the `volatile` keyword with the `RB_GC_GUARD` macro.
35
+ - Moved to using module constants for the _FizzBuzz_ specific strings values e.g., _Fizz_, _Buzz_ and _FizzBuzz_ to
36
+ improve performance since constants are allocated only once.
37
+ - Updated public GPG key.
38
+ - Updated public signing key.
39
+ - Updated Ruby gem dependencies.
40
+ - Removed surplus `for`-loop replacing it with a simpler `while`-loop.
41
+ - Removed surplus license headers from each file.
42
+ - Removed deprecated `Gem::Specification#has_rdoc=`.
43
+ - Removed integration with services like _Coveralls_, _Code Climate_ and _Gemnasium_.
44
+ - Addressed some of the _GCC_ compiler warnings.
45
+
46
+ ### Fixed
47
+
48
+ - Resolved Bundler issues by updating its version prior to installing Ruby gems when on _Travis CI_.
49
+ - Fixed pattern for test files in `Guardfile`.
50
+ - Addressed `RuntimeError` caused by modification of a frozen string.
51
+
52
+ ### Deprecated
53
+
54
+ - Retired support and testing with Ruby _1.9.x_, _2.0.x_, _2.1.x_, _2.2.x_ and _2.3.x_ on _Travis CI_.
55
+ - Retired support and testing for _Rubinius_ on _Travis CI_.
56
+ - Retried testing with Ruby _head_ on _Travis CI_.
57
+
58
+ ## [0.7.0] - 2014-12-15
59
+ ### Added
60
+
61
+ - Added `to_hash`, `as_json`, `to_json` and `from_json` (_singleton_) to the _FizzBuzz_ class.
62
+ - Added rudimentary `Vagrantfile` that can be used to build a development environment.
63
+ - Added the `Guard` Ruby gem for convenience, with an appropriate `Guardfile`.
64
+ - Added _LLVM_ (`clang`) compiler to build with to _Travis CI_.
65
+
66
+ ### Changed
67
+
68
+ - Re-factored `fizzbuzz` (_singleton_) from the _FizzBuzz_ class to speed it up.
69
+ - Re-factored tests to utilise modern version of the `test-unit` Ruby gem.
70
+ - Re-factored and cleaned up small portions of code and documentation.
71
+ - Updated `Rakefile` to no longer run `test` before `benchmark`.
72
+
73
+ ### Fixed
74
+
75
+ - Correctly return `Enumerator` when integrating with the _Range_ class.
76
+ - Fixed benchmarks concerning _Array_ and _Range_ integration.
77
+ - Fixed _Travis CI_ build against _Rubinius_.
78
+ - Fixed build to make it work with _C++_ compilers.
79
+ - Fixed version number to comply with [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
80
+
81
+ ### Deprecated
82
+
83
+ - No longer use of `Enumerable#entries` in the _Array_ integration, achieving
84
+ better performance.
85
+ - Retired testing with Ruby _1.9.2_ and _2.1.0_, and added _2.1.5_ on _Travis CI_.
86
+ - Removed _BitDeli_ badge.
87
+
88
+ ## [0.6.0] - 2014-02-23
89
+ ### Added
90
+
91
+ - Added Ruby _2.1.0_ to _Travis CI_.
92
+ - Added _BitDeli_ and _Gemnasium_ integration.
93
+
94
+ ### Changed
95
+
96
+ - Updated development dependencies.
97
+ - Re-factored and cleaned up small portions of code.
98
+ - Made _Rake_ `test` task to be the default tasks.
99
+ - Updated the `.gitignore` file to cover _Bundler_, _rbenv_, etc.
100
+
101
+ ### Fixed
102
+
103
+ - Fixed issue reported by _LLVM_ (`clang`).
104
+
105
+ ## [0.5.0] - 2013-11-26
106
+ ### Added
107
+
108
+ - Added integration with Array and Range types.
109
+ - Added simple benchmark.
110
+
111
+ ## [0.4.0] - 2013-11-18
112
+ ### Added
113
+
114
+ - Added _Coveralls_ and _Code Climate_ integration (and hence improved code test coverage).
115
+
116
+ ### Changed
117
+
118
+ - Improved error handling and made code more resilient to errors.
119
+
120
+ ### Fixed
121
+
122
+ - Fixed formatting and white spaces.
123
+
124
+ ### Deprecated
125
+
126
+ - Retired support for Ruby 1.8.x (no support for _MRI_, _Ruby Enterprise Edition_ and _Rubinius_).
127
+
128
+ ## [0.3.0] - 2013-08-31
129
+ ### Added
130
+
131
+ - Added custom exceptions and improved error handling.
132
+ - Added more variety of Rubies on which tests are being run with _Travis CI_.
133
+ - Added project to [RubyGems](http://rubygems.org) so it can be installed with
134
+ just `gem install ruby-fizzbuzz` command.
135
+
136
+ ### Changed
137
+
138
+ - Renamed project from _fizzbuzz_ to _ruby-fizzbuzz_ to avoid clashes with other
139
+ Ruby gems hosted on _RubyGems_ web site.
140
+ - Made `mkmf` in `extconf.rb` more user-friendly (it now reports missing build-time
141
+ dependencies better).
142
+ - Split Ruby gem specification (or _gemspec_ if you wish) away from _Rakefile_
143
+ into its own file (namely `ruby-fizzbuzz.gemspec`).
144
+ - Improved documentation and removed bunch of small code smells.
145
+
146
+ ## [0.2.0] - 2012-09-29
147
+ ### Added
148
+
149
+ - Added `is_fizz?`, `is_buzz?` and `is_fizzbuzz?` singleton methods to _FizzBuzz_ class.
150
+ - Added `fizz?`, `buzz?` and `fizzbuzz?` methods to the _Integer_ class via a monkey-patch
151
+ for convenience. ([#2](https://github.com/kwilczynski/ruby-fizzbuzz/issues/2))
152
+
153
+ ### Changed
154
+
155
+ - Changed behaviour of the `FizzBuzz#[]` singleton method, so it will yield a _FizzBuzz_
156
+ result for a given arbitrary Integer value. ([#1](https://github.com/kwilczynski/ruby-fizzbuzz/issues/1))
157
+ - Re-factored code to make it cleaner, and added more tests and improved coverage.
158
+ - Re-factored `FizzBuzz` so it now does not assume that we always want to calculate
159
+ results from `1` to `n` -- it is now possible to calculate _FizzBuzz_ results for
160
+ given `n`, `m` values, where `n` denotes start and `m` denotes stop value.
161
+
162
+ ## [0.1.0] - 2012-09-27
163
+ ### Added
164
+
165
+ - First version of FizzBuzz.
166
+
167
+ [Unreleased]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.9.0...HEAD
168
+ [0.8.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.8.0...v0.9.0
169
+ [0.7.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.7.0...v0.8.0
170
+ [0.6.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.6.0...v0.7.0
171
+ [0.5.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.4.0...v0.5.0
172
+ [0.4.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.3.0...v0.4.0
173
+ [0.3.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.2.0...v0.3.0
174
+ [0.2.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/v0.1.0...v0.2.0
175
+ [0.1.0]: https://github.com/kwilczynski/ruby-fizzbuzz/compare/0a6b1ba...v0.1.0
data/COPYRIGHT CHANGED
@@ -1 +1 @@
1
- Copyright 2012-2014 Krzysztof Wilczynski
1
+ Copyright 2012-2020 Krzysztof Wilczyński
@@ -0,0 +1,46 @@
1
+ # Yet another FizzBuzz in Ruby!
2
+
3
+ [![Build Status](https://travis-ci.org/kwilczynski/ruby-fizzbuzz.svg)](https://travis-ci.org/kwilczynski/ruby-fizzbuzz)
4
+ [![Documentation Status](https://inch-ci.org/github/kwilczynski/ruby-fizzbuzz.svg)](https://inch-ci.org/github/kwilczynski/ruby-fizzbuzz)
5
+ [![Gem Version](https://badge.fury.io/rb/ruby-fizzbuzz.svg)](http://badge.fury.io/rb/ruby-fizzbuzz)
6
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
+
8
+ ## Introduction
9
+
10
+ Provides simple and fast solution to a popular [FizzBuzz](https://en.wikipedia.org/wiki/FizzBuzz)
11
+ problem for Ruby.
12
+
13
+ Written in C as an example of using Ruby's C API - with the support for
14
+ arbitrary large numeric values via the Bignum class, or the Integer class
15
+ starting from Ruby version 2.4 onwards.
16
+
17
+ ## Table of Contents
18
+
19
+ 1. [Contributing](#contributing)
20
+ 2. [Versioning](#versioning)
21
+ 3. [Author](#author)
22
+ 4. [Copyright](#copyright)
23
+ 5. [License](#license)
24
+
25
+ ## Contributing
26
+
27
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for best practices and instructions on
28
+ setting up your development environment.
29
+
30
+ ## Versioning
31
+
32
+ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
33
+ For the versions available, see the tags on this repository.
34
+
35
+ ## Author
36
+
37
+ Krzysztof Wilczyński (<kw@linux.com>)
38
+
39
+ ## Copyright
40
+
41
+ Copyright 2012-2020 Krzysztof Wilczyński
42
+
43
+ ## License
44
+
45
+ This project is licensed under the terms of the Apache License, Version 2.0 license.
46
+ To view the full license see the included [LICENSE](LICENSE) file.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.8.0
@@ -1,106 +1,78 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # -*- encoding: utf-8 -*-
4
-
5
- # :enddoc:
6
-
7
- #
8
- # fizzbuzz
9
- #
10
- # Copyright 2012-2014 Krzysztof Wilczynski
11
- #
12
- # Licensed under the Apache License, Version 2.0 (the "License");
13
- # you may not use this file except in compliance with the License.
14
- # You may obtain a copy of the License at
15
- #
16
- # http://www.apache.org/licenses/LICENSE-2.0
17
- #
18
- # Unless required by applicable law or agreed to in writing, software
19
- # distributed under the License is distributed on an "AS IS" BASIS,
20
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- # See the License for the specific language governing permissions and
22
- # limitations under the License.
23
- #
24
-
25
3
  require 'optparse'
26
4
 
27
5
  begin
28
6
  require 'fizzbuzz'
29
7
  rescue LoadError
30
- require 'rubygems'
31
- require 'fizzbuzz'
8
+ abort "\n" + (<<-EOS).gsub(/^[ ]+/, '') + "\n"
9
+ You appear to be missing the ruby-fizzbuzz Ruby gem. Try
10
+ installing this missing dependency before you can run
11
+ this executable. To install the ruby-fizzbuzz Ruby gem,
12
+ try the following:
13
+
14
+ gem install ruby-fizzbuzz
15
+ EOS
32
16
  end
33
17
 
34
- script_name = File.basename($0)
18
+ script_name = File.basename($PROGRAM_NAME)
35
19
 
36
20
  start = 1
37
21
  stop = 100
38
22
 
23
+ line = false
39
24
  reverse = false
40
25
 
41
- parser = OptionParser.new do |option|
42
- option.banner = <<-EOS
26
+ OptionParser.new do |option|
27
+ option.banner = (<<-EOS).gsub(/^[ ]{,4}/, '')
28
+ Yet another FizzBuzz in Ruby.
43
29
 
44
- Yet another FizzBuzz in Ruby.
30
+ Usage:
45
31
 
46
- Usage:
47
-
48
- #{option.summary_indent}#{script_name} [--start <NUMBER>] [--stop <NUMBER>] [--reverse]
49
- #{option.summary_indent}#{script_name} [--version] [--help]
32
+ #{option.summary_indent}#{script_name} [--start <NUMBER>] [--stop <NUMBER>] [--reverse]
33
+ #{option.summary_indent}#{script_name} [--version] [--help]
50
34
  EOS
51
35
 
52
36
  option.separator "\nOptions:\n\n"
53
37
 
54
- option.on('--start <NUMBER>',
55
- "Specify the start value (default: #{start})."
56
- ) do | value|
38
+ option.on('--start <NUMBER>', "Specify the start value (default: #{start}).") do |value|
57
39
  start = value.to_i if value
58
40
  end
59
41
 
60
- option.on('--stop <NUMBER>',
61
- "Specify the stop value (default: #{stop})."
62
- ) do |value|
42
+ option.on('--stop <NUMBER>', "Specify the stop value (default: #{stop}).") do |value|
63
43
  stop = value.to_i if value
64
44
  end
65
45
 
66
- option.on('--reverse',
67
- "Print results in a reverse order."
68
- ) do
46
+ option.on('--line', 'Print results in a single line.') do
47
+ line = true
48
+ end
49
+
50
+ option.on('--reverse', 'Print results in a reverse order.') do
69
51
  reverse = true
70
52
  end
71
53
 
72
- option.on('-v', '--version',
73
- 'Show version number.'
74
- ) do
54
+ option.on('-v', '--version', 'Show version number.') do
75
55
  puts FizzBuzz::VERSION
76
56
  exit
77
57
  end
78
58
 
79
- option.on('-h', '--help',
80
- 'Display this help message.'
81
- ) do
59
+ option.on('-h', '--help', 'Display this help message.') do
82
60
  puts option.help
83
61
  exit
84
62
  end
85
63
 
86
- option.separator <<-EOS
64
+ option.separator "\n" + (<<-EOS).gsub(/^[ ]{,4}/, '')
65
+ Note:
87
66
 
88
- Note:
89
-
90
- By default, the results from #{start} to #{stop} will be shown in a descending order.
67
+ By default, the results from #{start} to #{stop} will be shown in a descending order.
91
68
  EOS
92
-
93
- option.separator "\n"
94
- end
95
-
96
- parser.parse!
69
+ end.parse!
97
70
 
98
71
  begin
99
- FizzBuzz.fizzbuzz(start, stop, reverse) {|i| puts i }
72
+ FizzBuzz.fizzbuzz(start, stop, reverse) do |i|
73
+ print format('%s%s', i, line ? ' ' : "\n")
74
+ end
100
75
  rescue => e
101
- puts "An error occurred: #{e.to_s}"
76
+ puts "An error occurred: #{e}"
102
77
  exit 1
103
78
  end
104
-
105
- # vim: set ts=2 sw=2 sts=2 et :
106
- # encoding: utf-8
@@ -1,26 +1,18 @@
1
- /* :enddoc: */
2
-
3
- /*
4
- * common.h
5
- *
6
- * Copyright 2012-2014 Krzysztof Wilczynski
7
- *
8
- * Licensed under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License.
10
- * You may obtain a copy of the License at
11
- *
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- */
20
-
21
1
  #if !defined(_COMMON_H)
22
2
  #define _COMMON_H 1
23
3
 
4
+ #if !defined(_GNU_SOURCE)
5
+ # define _GNU_SOURCE 1
6
+ #endif
7
+
8
+ #if !defined(_BSD_SOURCE)
9
+ # define _BSD_SOURCE 1
10
+ #endif
11
+
12
+ #if !defined(_DEFAULT_SOURCE)
13
+ # define _DEFAULT_SOURCE 1
14
+ #endif
15
+
24
16
  #if defined(__cplusplus)
25
17
  extern "C" {
26
18
  #endif
@@ -29,19 +21,39 @@ extern "C" {
29
21
  #include <assert.h>
30
22
  #include <ruby.h>
31
23
 
32
- #if !(defined(INT8_MIN) || defined(INT8_MAX))
33
- typedef signed char int8_t;
24
+ #if !defined(ANYARGS)
25
+ # if defined(__cplusplus)
26
+ # define ANYARGS ...
27
+ # else
28
+ # define ANYARGS
29
+ # endif
34
30
  #endif
35
31
 
36
- #if !(defined(UINT8_MIN) || defined(UINT8_MAX))
37
- typedef unsigned char uint8_t;
32
+ #if !defined(RB_UNUSED_VAR)
33
+ # if defined(__GNUC__)
34
+ # define RB_UNUSED_VAR(x) (x) __attribute__ ((unused))
35
+ # else
36
+ # define RB_UNUSED_VAR(x) (x)
37
+ # endif
38
38
  #endif
39
39
 
40
- #if defined(UNUSED)
41
- # undef(UNUSED)
40
+ #if !(defined(RB_LIKELY) || defined(RB_UNLIKELY))
41
+ # if defined(__GNUC__) && __GNUC__ >= 3
42
+ # define RB_LIKELY(x) (__builtin_expect(!!(x), 1))
43
+ # define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0))
44
+ # else
45
+ # define RB_LIKELY(x) (x)
46
+ # define RB_UNLIKELY(x) (x)
47
+ # endif
42
48
  #endif
43
49
 
44
- #define UNUSED(x) (void)(x)
50
+ #if !defined(RUBY_METHOD_FUNC)
51
+ # define RUBY_METHOD_FUNC(f) ((VALUE (*)(ANYARGS))(f))
52
+ #endif
53
+
54
+ #if defined(RUBY_INTEGER_UNIFICATION) || RUBY_API_VERSION_CODE >= 20400
55
+ # define HAVE_INTEGER_UNIFICATION 1
56
+ #endif
45
57
 
46
58
  #if !defined(CSTR2RVAL)
47
59
  # define CSTR2RVAL(x) ((x) == NULL ? Qnil : rb_str_new2(x))
@@ -68,5 +80,3 @@ typedef unsigned char uint8_t;
68
80
  #endif
69
81
 
70
82
  #endif /* _COMMON_H */
71
-
72
- /* vim: set ts=8 sw=4 sts=2 et : */