dancer 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: e269b43ddeb6eefae3fb07baf0d920e6d6420192
4
+ data.tar.gz: acc613349321fe054ab4d40d8c920958512bcc8b
5
+ SHA512:
6
+ metadata.gz: 78a6b1ddda62b4ff57d0cc2e51bef5c8a4d4b06fd19951adb0db89e76bb540a6245468cce8a3d873eeb399b8849cc76acfb857ed008c64f77e1ee856e2a85c86
7
+ data.tar.gz: 0dbf6789d4adde89e0b552e553ddc6a83f34f7e7c8ae501cd1278888615f27ae6bd19656976688cba1a0dcf81ab8a8310042980fa0a34c3ee96929c292da6a3f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /Gemfile.lock
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dancer.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+ guard :rspec, cmd: "bin/rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Steve Hoeksema
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Dancer
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dancer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem "dancer"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dancer
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dancer.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
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/_guard-core ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application '_guard-core' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "_guard-core")
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dancer"
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/guard ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'guard' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "guard")
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
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
data/dancer.gemspec ADDED
@@ -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
+ require "dancer/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dancer"
8
+ spec.version = Dancer::VERSION
9
+ spec.authors = ["Steve Hoeksema"]
10
+ spec.email = ["steve@kotiri.com"]
11
+
12
+ spec.summary = "Dancer steps through Time"
13
+ spec.description = "Dancer steps through Time"
14
+ spec.homepage = "https://github.com/steveh/dancer"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "guard-rspec"
25
+ spec.add_development_dependency "simplecov"
26
+ end
data/lib/dancer.rb ADDED
@@ -0,0 +1,102 @@
1
+ require "dancer/version"
2
+ require "dancer/constants"
3
+ require "dancer/factories"
4
+ require "dancer/defined"
5
+
6
+ class Dancer
7
+ # Start can be a Time or an Integer
8
+ # End can be a Time or an Integer
9
+ # Step is an Integer
10
+ def initialize(start_at, end_at, step, exclude_end = false)
11
+ unless step
12
+ fail ArgumentError, "step is required"
13
+ end
14
+
15
+ @start_at = start_at
16
+ @end_at = end_at
17
+ @step = step
18
+ @exclude_end = exclude_end
19
+
20
+ if start_at && end_at
21
+ if start_at > end_at
22
+ @operator = :-
23
+ @comparator = :>
24
+ else
25
+ @operator = :+
26
+ @comparator = :<
27
+ end
28
+ end
29
+ end
30
+
31
+ attr_reader :start_at, :end_at, :step, :operator, :comparator
32
+
33
+ def exclude_end?
34
+ @exclude_end
35
+ end
36
+
37
+ # Total number of points in the range
38
+ def size
39
+ return unless bounded?
40
+
41
+ ((end_at.public_send(operator, 1) - start_at) / step).abs
42
+ end
43
+
44
+ alias count size
45
+ alias length size
46
+
47
+ # Range of start and end of slice
48
+ def range
49
+ return unless bounded?
50
+
51
+ start_at..end_at
52
+ end
53
+
54
+ # Enumerator for each start time
55
+ def each_time
56
+ return enum_for(:each_time) unless block_given?
57
+ return self unless bounded?
58
+
59
+ current = start_at
60
+ while current.public_send(comparator, end_at)
61
+ yield current
62
+ current = current.public_send(operator, step)
63
+ end
64
+ self
65
+ end
66
+
67
+ # Enumerator for each time range
68
+ def each_range
69
+ return enum_for(:each_range) unless block_given?
70
+ return self unless bounded?
71
+
72
+ current = start_at
73
+ while current.public_send(comparator, end_at)
74
+ current_end_at = current.public_send(operator, step) - (0.public_send(operator, 1))
75
+ current_range = current..current_end_at
76
+ yield current_range
77
+ current = current.public_send(operator, step)
78
+ end
79
+ self
80
+ end
81
+
82
+ # Number of seconds covered by the slice
83
+ def duration
84
+ return unless bounded?
85
+
86
+ (end_at - start_at).abs + 1
87
+ end
88
+
89
+ alias to_i duration
90
+
91
+ def bounded?
92
+ start_at && end_at
93
+ end
94
+
95
+ def to_s
96
+ "#{start_at.inspect}..#{end_at.inspect} (step: #{step})"
97
+ end
98
+
99
+ def inspect
100
+ "#<Dancer #{to_s}>"
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ class Dancer
2
+ Infinity = Float::INFINITY
3
+ end
@@ -0,0 +1,26 @@
1
+ class Dancer
2
+ Defined = Struct.new(:step) do
3
+ def unbounded
4
+ Dancer.unbounded(step)
5
+ end
6
+
7
+ # Create a timeslice from a range
8
+ def range(range)
9
+ Dancer.range(range, step)
10
+ end
11
+
12
+ # Create a timeslice from a start time and a number of a points
13
+ def extent(start_at, size, exclude_end = false)
14
+ Dancer.extent(start_at, size, step, exclude_end)
15
+ end
16
+
17
+ # Create a timeslice from a list of start times
18
+ def keys(keys, exclude_end = false)
19
+ Dancer.keys(keys, step, exclude_end)
20
+ end
21
+
22
+ def new(start_at, end_at, exclude_end = false)
23
+ Dancer.new(start_at, end_at, step, exclude_end)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ class Dancer
2
+ # Create an unbounded timeslice
3
+ def self.unbounded(step)
4
+ new(nil, nil, step)
5
+ end
6
+
7
+ # Create a timeslice from a range
8
+ def self.range(range, step)
9
+ new(range.begin, range.end, step, range.exclude_end?)
10
+ end
11
+
12
+ # Create a timeslice from a start time and a number of a points
13
+ def self.extent(start_at, size, step, exclude_end = false)
14
+ end_at = start_at + (step * size) - 1
15
+
16
+ new(start_at, end_at, step, exclude_end)
17
+ end
18
+
19
+ # Create a timeslice from a list of start times
20
+ def self.keys(keys, step, exclude_end = false)
21
+ start_at = keys.min
22
+ end_at = keys.max ? (keys.max + step - 1) : nil
23
+
24
+ new(start_at, end_at, step, exclude_end)
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ class Dancer
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dancer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Hoeksema
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-22 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
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: Dancer steps through Time
70
+ email:
71
+ - steve@kotiri.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/_guard-core
85
+ - bin/console
86
+ - bin/guard
87
+ - bin/rspec
88
+ - bin/setup
89
+ - dancer.gemspec
90
+ - lib/dancer.rb
91
+ - lib/dancer/constants.rb
92
+ - lib/dancer/defined.rb
93
+ - lib/dancer/factories.rb
94
+ - lib/dancer/version.rb
95
+ homepage: https://github.com/steveh/dancer
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Dancer steps through Time
119
+ test_files: []