hrt_bus 0.0.6 → 0.0.7
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.
- data/CHANGELOG.md +4 -0
- data/README.md +23 -23
- data/hrt_bus.gemspec +2 -2
- data/lib/hrt_bus/bus.rb +38 -6
- data/lib/hrt_bus/version.rb +1 -1
- data/spec/factories/bus.rb +1 -0
- data/spec/models/bus/bus_attributes_spec.rb +1 -0
- data/spec/models/bus/bus_methods_spec.rb +77 -0
- data/spec/models/bus/bus_validations_spec.rb +14 -0
- metadata +4 -4
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # hrt_bus
         | 
| 2 2 |  | 
| 3 | 
            -
            Ruby gem for  | 
| 3 | 
            +
            Ruby gem for real-time Hampton Roads Transit bus location data
         | 
| 4 4 |  | 
| 5 5 | 
             
            ## Installation
         | 
| 6 6 |  | 
| @@ -8,7 +8,7 @@ Ruby gem for public HRT bus location data | |
| 8 8 |  | 
| 9 9 | 
             
            ## Examples
         | 
| 10 10 |  | 
| 11 | 
            -
            ###  | 
| 11 | 
            +
            ### A Bus as a Ruby ActiveModel object
         | 
| 12 12 |  | 
| 13 13 | 
             
                HrtBus::Rider.new(:route_id => "20", :direction => "inbound").bus
         | 
| 14 14 |  | 
| @@ -21,6 +21,27 @@ Ruby gem for public HRT bus location data | |
| 21 21 | 
             
                  attr_accessor :time = Sat, 03 Mar 2012 23:24:28 +0000,
         | 
| 22 22 | 
             
                >
         | 
| 23 23 |  | 
| 24 | 
            +
            ### Is my bus late?
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                HrtBus::Rider.new(:route_id => "20", :direction => "inbound").bus.late?
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ### Send yourself a SMS or Tweet when your bus is close!
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                (1..15).each do |i|
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  rider =  HrtBus::Rider.new(:route_id  => "2",
         | 
| 33 | 
            +
                                             :direction => "inbound",
         | 
| 34 | 
            +
                                             :lat       => "36.870347",
         | 
| 35 | 
            +
                                             :lon       => "-76.301163" )
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  if rider.bus.present? && rider.distance_to_bus <= 3
         | 
| 38 | 
            +
                    # Do something really cool like send a SMS or Tweet!
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  sleep 30
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 24 45 | 
             
            ### Generate a static Google Map for a bus
         | 
| 25 46 |  | 
| 26 47 | 
             
                HrtBus::Rider.new(:route_id => "15", :direction => "outbound").bus.static_map
         | 
| @@ -55,27 +76,6 @@ Ruby gem for public HRT bus location data | |
| 55 76 | 
             
                ]
         | 
| 56 77 | 
             
                ...
         | 
| 57 78 |  | 
| 58 | 
            -
            ### Determine if a bus is valid
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                HrtBus::Bus.active_buses.select { |bus| bus.route_id => "2" }.first.valid?
         | 
| 61 | 
            -
             | 
| 62 | 
            -
            ### Send yourself a SMS or Tweet when your bus is close!
         | 
| 63 | 
            -
             | 
| 64 | 
            -
                (1..15).each do |i|
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                  rider =  HrtBus::Rider.new(:route_id  => "2",
         | 
| 67 | 
            -
                                             :direction => "inbound",
         | 
| 68 | 
            -
                                             :lat       => "36.870347",
         | 
| 69 | 
            -
                                             :lon       => "-76.301163" )
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  if rider.bus.present? && rider.distance_to_bus <= 3
         | 
| 72 | 
            -
                    # Do something really cool like send a SMS or Tweet!
         | 
| 73 | 
            -
                  end
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                  sleep 30
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                end
         | 
| 78 | 
            -
             | 
| 79 79 | 
             
            ## Contributing to hrt_bus
         | 
| 80 80 |  | 
| 81 81 | 
             
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
         | 
    
        data/hrt_bus.gemspec
    CHANGED
    
    | @@ -8,8 +8,8 @@ Gem::Specification.new do |s| | |
| 8 8 | 
             
              s.authors     = ["Brian Douglas Smith"]
         | 
| 9 9 | 
             
              s.email       = ["m.b1205@gmail.com"]
         | 
| 10 10 | 
             
              s.homepage    = "https://github.com/bds/hrt_bus"
         | 
| 11 | 
            -
              s.summary     = %q{ | 
| 12 | 
            -
              s.description = %q{ | 
| 11 | 
            +
              s.summary     = %q{Real-time Hampton Roads Transit bus location data}
         | 
| 12 | 
            +
              s.description = %q{Bus number, route, GPS coordiantes, early/ontime/late and more}
         | 
| 13 13 |  | 
| 14 14 | 
             
              s.rubyforge_project = "hrt_bus"
         | 
| 15 15 |  | 
    
        data/lib/hrt_bus/bus.rb
    CHANGED
    
    | @@ -3,7 +3,7 @@ module HrtBus | |
| 3 3 | 
             
                include ActiveModel::Validations
         | 
| 4 4 | 
             
                include ActiveModel::Serializers::JSON
         | 
| 5 5 |  | 
| 6 | 
            -
                ATTRIBUTES = [ :id, :time, :direction, :lat, :lon, :route_id ]
         | 
| 6 | 
            +
                ATTRIBUTES = [ :id, :time, :direction, :lat, :lon, :route_id, :adherence ]
         | 
| 7 7 |  | 
| 8 8 | 
             
                DIRECTIONS = { "1" => "inbound",
         | 
| 9 9 | 
             
                               "2" => "outbound" }.freeze
         | 
| @@ -13,6 +13,7 @@ module HrtBus | |
| 13 13 | 
             
                validates_numericality_of :route_id, greater_than: 0
         | 
| 14 14 | 
             
                validates_numericality_of :lat, greater_than: 0
         | 
| 15 15 | 
             
                validates_numericality_of :lon, less_than: 0
         | 
| 16 | 
            +
                validates_numericality_of :adherence
         | 
| 16 17 | 
             
                validates :direction, :inclusion => { :in => DIRECTIONS.values }
         | 
| 17 18 |  | 
| 18 19 | 
             
                validates :id, :time, :direction, :lat, :lon, :route_id, :presence => true
         | 
| @@ -38,6 +39,18 @@ module HrtBus | |
| 38 39 | 
             
                  send(key)
         | 
| 39 40 | 
             
                end
         | 
| 40 41 |  | 
| 42 | 
            +
                def early?
         | 
| 43 | 
            +
                  self.adherence < 0
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def ontime?
         | 
| 47 | 
            +
                  self.adherence == 0
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def late?
         | 
| 51 | 
            +
                  self.adherence > 0
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 41 54 | 
             
                def static_map
         | 
| 42 55 | 
             
                  map = GoogleStaticMap.new(:width => 960, :height => 640)
         | 
| 43 56 | 
             
                  map.markers << MapMarker.new(:color => "blue",
         | 
| @@ -60,18 +73,26 @@ module HrtBus | |
| 60 73 | 
             
                  parsed = ::CSV.new(curl.body_str, { :headers => true, :skip_blanks => true })
         | 
| 61 74 |  | 
| 62 75 | 
             
                  parsed.each do |row|
         | 
| 63 | 
            -
                    time, date, id, lat_lon, valid, route_id, direction  = row[0],
         | 
| 76 | 
            +
                    time, date, id, lat_lon, valid, adherence, route_id, direction  = row[0],
         | 
| 64 77 | 
             
                                                                           row[1],
         | 
| 65 78 | 
             
                                                                           row[2],
         | 
| 66 79 | 
             
                                                                           row[3],
         | 
| 67 80 | 
             
                                                                           row[4],
         | 
| 81 | 
            +
                                                                           row[5],
         | 
| 68 82 | 
             
                                                                           row[7],
         | 
| 69 83 | 
             
                                                                           DIRECTIONS[row[8]]
         | 
| 70 84 |  | 
| 71 85 | 
             
                    time     = HrtBus::Parse.time(time, date)
         | 
| 72 86 | 
             
                    lat, lon = HrtBus::Parse.geo(lat_lon)
         | 
| 73 87 |  | 
| 74 | 
            -
                    bus = new(: | 
| 88 | 
            +
                    bus = new(:time      => time,
         | 
| 89 | 
            +
                              :id        => id,
         | 
| 90 | 
            +
                              :lat       => lat,
         | 
| 91 | 
            +
                              :lon       => lon,
         | 
| 92 | 
            +
                              :adherence => adherence,
         | 
| 93 | 
            +
                              :route_id  => route_id,
         | 
| 94 | 
            +
                              :route_id  => route_id,
         | 
| 95 | 
            +
                              :direction => direction)
         | 
| 75 96 |  | 
| 76 97 | 
             
                    buses << bus if bus.valid?
         | 
| 77 98 | 
             
                  end
         | 
| @@ -91,18 +112,30 @@ module HrtBus | |
| 91 112 | 
             
                  parsed = ::CSV.new(curl.body_str, { :headers => true, :skip_blanks => true })
         | 
| 92 113 |  | 
| 93 114 | 
             
                  parsed.each do |row|
         | 
| 94 | 
            -
             | 
| 115 | 
            +
             | 
| 116 | 
            +
                    time, date, id, lat_lon, valid, adherence, route_id, direction  = row[0],
         | 
| 95 117 | 
             
                                                                           row[1],
         | 
| 96 118 | 
             
                                                                           row[2],
         | 
| 97 119 | 
             
                                                                           row[3],
         | 
| 98 120 | 
             
                                                                           row[4],
         | 
| 121 | 
            +
                                                                           row[5],
         | 
| 99 122 | 
             
                                                                           row[7],
         | 
| 100 123 | 
             
                                                                           DIRECTIONS[row[8]]
         | 
| 101 124 |  | 
| 125 | 
            +
             | 
| 102 126 | 
             
                    time     = HrtBus::Parse.time(time, date)
         | 
| 103 127 | 
             
                    lat, lon = HrtBus::Parse.geo(lat_lon)
         | 
| 104 128 |  | 
| 105 | 
            -
                     | 
| 129 | 
            +
                    bus = new(:time      => time,
         | 
| 130 | 
            +
                              :id        => id,
         | 
| 131 | 
            +
                              :lat       => lat,
         | 
| 132 | 
            +
                              :lon       => lon,
         | 
| 133 | 
            +
                              :adherence => adherence,
         | 
| 134 | 
            +
                              :route_id  => route_id,
         | 
| 135 | 
            +
                              :route_id  => route_id,
         | 
| 136 | 
            +
                              :direction => direction)
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                    buses << bus
         | 
| 106 139 | 
             
                  end
         | 
| 107 140 | 
             
                  buses
         | 
| 108 141 | 
             
                end
         | 
| @@ -110,4 +143,3 @@ module HrtBus | |
| 110 143 | 
             
              end
         | 
| 111 144 |  | 
| 112 145 | 
             
            end
         | 
| 113 | 
            -
             | 
    
        data/lib/hrt_bus/version.rb
    CHANGED
    
    
    
        data/spec/factories/bus.rb
    CHANGED
    
    
| @@ -11,6 +11,7 @@ describe HrtBus::Bus do | |
| 11 11 |  | 
| 12 12 | 
             
                  it "should return a collection of valid buses" do
         | 
| 13 13 | 
             
                    buses.should be_a_kind_of(Enumerable) 
         | 
| 14 | 
            +
                    buses.should_not be_empty
         | 
| 14 15 | 
             
                    buses.each { |bus| bus.should be_valid }
         | 
| 15 16 | 
             
                    buses.first.should be_a_kind_of(HrtBus::Bus) 
         | 
| 16 17 | 
             
                  end
         | 
| @@ -44,4 +45,80 @@ describe HrtBus::Bus do | |
| 44 45 | 
             
                end
         | 
| 45 46 |  | 
| 46 47 | 
             
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              describe "early?" do
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                context "the bus is early" do
         | 
| 52 | 
            +
                  it "should return true" do
         | 
| 53 | 
            +
                    bus = Factory.build(:bus, :adherence => -2)
         | 
| 54 | 
            +
                    bus.early?.should be_true
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                context "the bus is on time" do
         | 
| 59 | 
            +
                  it "should return false" do
         | 
| 60 | 
            +
                    bus = Factory.build(:bus, :adherence => 0)
         | 
| 61 | 
            +
                    bus.early?.should be_false
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                context "the bus is late" do
         | 
| 66 | 
            +
                  it "should return false" do
         | 
| 67 | 
            +
                    bus = Factory.build(:bus, :adherence => 4)
         | 
| 68 | 
            +
                    bus.early?.should be_false
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              describe "ontime?" do
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                context "the bus is early" do
         | 
| 77 | 
            +
                  it "should return false" do
         | 
| 78 | 
            +
                    bus = Factory.build(:bus, :adherence => -2)
         | 
| 79 | 
            +
                    bus.ontime?.should be_false
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                context "the bus is on time" do
         | 
| 84 | 
            +
                  it "should return true" do
         | 
| 85 | 
            +
                    bus = Factory.build(:bus, :adherence => 0)
         | 
| 86 | 
            +
                    bus.ontime?.should be_true
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                context "the bus is late" do
         | 
| 91 | 
            +
                  it "should return false" do
         | 
| 92 | 
            +
                    bus = Factory.build(:bus, :adherence => 4)
         | 
| 93 | 
            +
                    bus.ontime?.should be_false
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              describe "late?" do
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                context "the bus is early" do
         | 
| 102 | 
            +
                  it "should return false" do
         | 
| 103 | 
            +
                    bus = Factory.build(:bus, :adherence => -2)
         | 
| 104 | 
            +
                    bus.late?.should be_false
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                context "the bus is on time" do
         | 
| 109 | 
            +
                  it "should return true" do
         | 
| 110 | 
            +
                    bus = Factory.build(:bus, :adherence => 0)
         | 
| 111 | 
            +
                    bus.late?.should be_false
         | 
| 112 | 
            +
                  end
         | 
| 113 | 
            +
                end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                context "the bus is late" do
         | 
| 116 | 
            +
                  it "should return false" do
         | 
| 117 | 
            +
                    bus = Factory.build(:bus, :adherence => 4)
         | 
| 118 | 
            +
                    bus.late?.should be_true
         | 
| 119 | 
            +
                  end
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
              end
         | 
| 123 | 
            +
             | 
| 47 124 | 
             
            end
         | 
| @@ -72,6 +72,20 @@ describe HrtBus::Bus do | |
| 72 72 | 
             
                  bus.errors.messages[:route_id].first.should match(/is not a number/)
         | 
| 73 73 | 
             
                end
         | 
| 74 74 |  | 
| 75 | 
            +
                it "should validate_presence_of :adherence" do
         | 
| 76 | 
            +
                  bus.should be_valid
         | 
| 77 | 
            +
                  bus.adherence = nil
         | 
| 78 | 
            +
                  bus.should_not be_valid
         | 
| 79 | 
            +
                  bus.errors.messages[:adherence].first.should match(/is not a number/)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                it "should validate_numericality :adherence" do
         | 
| 83 | 
            +
                  bus.should be_valid
         | 
| 84 | 
            +
                  bus.adherence = "late"
         | 
| 85 | 
            +
                  bus.should_not be_valid
         | 
| 86 | 
            +
                  bus.errors.messages[:adherence].first.should match(/is not a number/)
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 75 89 | 
             
              end
         | 
| 76 90 |  | 
| 77 91 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            name: hrt_bus
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 4 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0.0. | 
| 5 | 
            +
              version: 0.0.7
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors: 
         | 
| 8 8 | 
             
            - Brian Douglas Smith
         | 
| @@ -10,7 +10,7 @@ autorequire: | |
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 12 |  | 
| 13 | 
            -
            date: 2012-03- | 
| 13 | 
            +
            date: 2012-03-10 00:00:00 Z
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 16 16 | 
             
              name: activemodel
         | 
| @@ -155,7 +155,7 @@ dependencies: | |
| 155 155 | 
             
                    version: "0"
         | 
| 156 156 | 
             
              type: :development
         | 
| 157 157 | 
             
              version_requirements: *id013
         | 
| 158 | 
            -
            description:  | 
| 158 | 
            +
            description: Bus number, route, GPS coordiantes, early/ontime/late and more
         | 
| 159 159 | 
             
            email: 
         | 
| 160 160 | 
             
            - m.b1205@gmail.com
         | 
| 161 161 | 
             
            executables: []
         | 
| @@ -223,7 +223,7 @@ rubyforge_project: hrt_bus | |
| 223 223 | 
             
            rubygems_version: 1.8.17
         | 
| 224 224 | 
             
            signing_key: 
         | 
| 225 225 | 
             
            specification_version: 3
         | 
| 226 | 
            -
            summary:  | 
| 226 | 
            +
            summary: Real-time Hampton Roads Transit bus location data
         | 
| 227 227 | 
             
            test_files: 
         | 
| 228 228 | 
             
            - spec/factories/bus.rb
         | 
| 229 229 | 
             
            - spec/factories/rider.rb
         |