catalogdb 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f1af3e70effd829aaeb9ac3d6d1a4fcb77d1a93e
4
- data.tar.gz: 05ae5750aec2241b51e2debb034d8e567056f726
3
+ metadata.gz: 2a16ac8ca3aa15c2aa18ae3948ef17133aaefd80
4
+ data.tar.gz: e8ee0455a183a2ac70bd0aadc3a783c1764583a0
5
5
  SHA512:
6
- metadata.gz: d028c63e7fe7bcfb470c4e741269e0b768e6ada86a2937ad7985d3c08760eca397e2fea57ac8ea14b588829846d7b0c132e91f3b96c5eb17e8c98b2712d4a852
7
- data.tar.gz: 0658b9132867a8d3423200e7005396e8a0ad5a24236315eac917b4a79ed270458ce2df62a9fa841e58fbed710a362e4f18d793348aed6a0b974cbfffc2929911
6
+ metadata.gz: 2eb5003ff87a85aa35156aeb1a66e8f1542e3443f1a750d869367d2342df45ffbd9add26b87637402c3ce8ea6cfdf5baa9ca3eec0606ae5eea189a6de6af1e83
7
+ data.tar.gz: d22cdc70923cc44d80ab3e3984523cdd1265be87d015955864ebb9eb663e8ddf629089d76361cb2d42a1bac489aff8f999038f8a9a9013fbd7647440da0f7f68
@@ -3,4 +3,9 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/catalogdb.rb
6
+ lib/catalogdb/reader.rb
6
7
  lib/catalogdb/version.rb
8
+ test/data/RUBY.md
9
+ test/helper.rb
10
+ test/test_reader.rb
11
+ test/test_version.rb
@@ -0,0 +1,138 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ module CatalogDb
5
+
6
+
7
+ class CardReader
8
+
9
+ include LogUtils::Logging
10
+
11
+
12
+ Card = Struct.new( :links, :categories ) ## use cats for categories - why? why not?
13
+
14
+
15
+ def self.from_url( src ) # note: src assumed a string
16
+ worker = Fetcher::Worker.new
17
+ self.from_string( worker.read_utf8!( src ) )
18
+ end
19
+
20
+ def self.from_file( path )
21
+ self.from_string( File.read_utf8( path ) )
22
+ end
23
+
24
+ def self.from_string( text )
25
+ self.new( text )
26
+ end
27
+
28
+
29
+ def initialize( text )
30
+ @text = text
31
+ end
32
+
33
+
34
+
35
+ ## example:
36
+ ## - [Sinatra HQ](http://sinatrarb.com)
37
+
38
+ LINK_ENTRY_REGEX = /\[
39
+ (?<title>[^\]]+) # 1st capture group (title)
40
+ \]
41
+ \(
42
+ (?<url>[^\)]+) # 2nd capture group (url)
43
+ \)
44
+ /x
45
+
46
+
47
+ def read
48
+
49
+ cards = []
50
+ stack = [] ## header/heading stack; note: last_stack is stack.size; starts w/ 0
51
+
52
+
53
+ # note: cut out; remove all html comments e.g. <!-- -->
54
+ # supports multi-line comments too (e.g. uses /m - make dot match newlines)
55
+ text = @text.gsub( /<!--.+?-->/m, '' ) ## todo/fix: track/log cut out comments!!!
56
+
57
+ text.each_line do |line|
58
+
59
+ logger.debug "line: >#{line}<"
60
+ line = line.rstrip ## remove (possible) trailing newline
61
+
62
+ ## todo/fix: add to event reader too!!! - Thanks/Meta
63
+ break if line =~ /^## (More|Thanks|Meta)/ # stop when hitting >## More< or Thanks or Meta section
64
+ next if line =~ /^\s*$/ # skip blank lines
65
+
66
+ m = nil
67
+ if line =~ /^[ ]*(#+)[ ]+/ ## heading/headers - note: must escpape #
68
+ s = StringScanner.new( line )
69
+ s.skip( /[ ]*/ ) ## skip whitespaces
70
+ markers = s.scan( /#+/)
71
+ level = markers.size
72
+ s.skip( /[ ]*/ ) ## skip whitespaces
73
+ title = s.rest.rstrip
74
+
75
+ logger.debug " heading level: #{level}, title: >#{title}<"
76
+
77
+ level_diff = level - stack.size
78
+
79
+ if level_diff > 0
80
+ logger.debug "[CardReader] up +#{level_diff}"
81
+ if level_diff > 1
82
+ logger.error "fatal: level step must be one (+1) is +#{level_diff}"
83
+ fail "[CardReader] level step must be one (+1) is +#{level_diff}"
84
+ end
85
+ elsif level_diff < 0
86
+ logger.debug "[CardReader] down #{level_diff}"
87
+ level_diff.abs.times { stack.pop }
88
+ stack.pop
89
+ else
90
+ ## same level
91
+ stack.pop
92
+ end
93
+ stack.push( [level,title] )
94
+ logger.debug " stack: #{stack.inspect}"
95
+
96
+ elsif line =~ /^([ ]*)-[ ]+/ ## list item
97
+
98
+ ## check indent level
99
+ ## note: skip sub list items for now (assume 2 or more spaces)
100
+ indent = $1.to_s
101
+ if indent.length >= 2
102
+ logger.debug " *** skip link entry w/ indent #{indent.length}: >#{line}<"
103
+ elsif( m=LINK_ENTRY_REGEX.match( line ) )
104
+ logger.debug " link entry: #{line}"
105
+
106
+ s = StringScanner.new( line )
107
+ s.skip( /[ ]*-[ ]*/ ) ## skip leading list
108
+
109
+
110
+ ## collect links e.g.
111
+ ## [["Lotus HQ", "http://lotusrb.org"],
112
+ ## [":octocat:", "https://github.com/lotus"],
113
+ ## [":gem:", "https://rubygems.org/gems/lotusrb"],
114
+ ## [":book:", "http://rubydoc.info/gems/lotusrb"]]
115
+
116
+ links = s.rest.scan( LINK_ENTRY_REGEX )
117
+ pp links
118
+
119
+ categories = stack.map {|it| it[1] }.join(' › ')
120
+ logger.debug " categories: #{categories}"
121
+
122
+ card = Card.new( links, categories )
123
+ ## pp card
124
+ cards << card
125
+ else
126
+ logger.debug " *** skip list item line: #{line}"
127
+ end
128
+ else
129
+ logger.debug " *** skip line: #{line}"
130
+ end
131
+ end
132
+
133
+ cards
134
+ end
135
+
136
+ end # class CardReader
137
+
138
+ end # module CatalogDb
@@ -4,7 +4,7 @@ module CatalogDb
4
4
 
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 1
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -0,0 +1,157 @@
1
+ Awesome Series @ Planet Ruby
2
+
3
+ [Rubies (Virtual Machines, Compilers, ...)](https://github.com/planetruby/awesome-rubies) •
4
+ [ActiveRecord](https://github.com/planetruby/awesome-activerecord) •
5
+ [Webframeworks (Micro, Macro, APIs, ...)](https://github.com/planetruby/awesome-webframeworks) •
6
+ [Static Generators (Sites, Books, Presentations, ...)](https://github.com/planetruby/awesome-staticgen) •
7
+ [Events (Conferences, Camps, Meetups, ...)](https://github.com/planetruby/awesome-events) •
8
+ [Blogs (News, Opinions, Podcasts, ...)](https://github.com/planetruby/awesome-blogs)
9
+
10
+
11
+ # Webframeworks
12
+
13
+ A collection of awesome Ruby web frameworks, libraries, tools, etc.
14
+
15
+
16
+ Note: :gem: stands for the RubyGems page, :octocat: stands for the GitHub page and :book: stands for the RubyDoc page.
17
+
18
+ ---
19
+
20
+ [ANNOUNCEMENT] Looking for awesome Ruby Gems? See the [Ruby Gems of the Week Series @ Planet Ruby](http://planetruby.github.io/gems).
21
+
22
+ ---
23
+
24
+ Contributions welcome. Anything missing? Send in a pull request. Thanks.
25
+
26
+
27
+ [Rack](#rack) •
28
+ [Rack Alternatives](#rack-alternatives) •
29
+ [Ruby on Rails](#ruby-on-rails) •
30
+ [Sinatra](#sinatra) •
31
+ [Volt](#volt) •
32
+ [Async Web (Socket) Frameworks](#async-web-socket-frameworks) •
33
+ [Web Service Frameworks](#web-service-frameworks) •
34
+ [Micro Framework Alternatives](#micro-framework-alternatives) •
35
+ ["Full Stack" Macro Framework Alternatives](#full-stack-macro-framework-alternatives) •
36
+ [Meta](#meta)
37
+
38
+
39
+ ## Rack
40
+
41
+ - [Rack HQ](http://rack.github.io) - [:octocat:](https://github.com/rack), [:gem:](https://rubygems.org/gems/rack), [:book:](http://rubydoc.info/gems/rack)
42
+
43
+ ## Rack Alternatives
44
+
45
+ - [the_metal :octocat:](https://github.com/tenderlove/the_metal) - a spike for thoughts about Rack 2.0
46
+
47
+ ## Ruby on Rails
48
+
49
+ _Batteries Included "Full Stack" Macro Framework_
50
+
51
+ - [Ruby on Rails HQ](http://rubyonrails.org) - [:octocat:](https://github.com/rails), [:gem:](https://rubygems.org/gems/rails), [:book:](http://rubydoc.info/gems/rails)
52
+ - [News & Updates](http://weblog.rubyonrails.org)
53
+
54
+ Extensions:
55
+
56
+ - [Hobo HQ](http://hobocentral.net) - [:octocat:](https://github.com/Hobo), [:gem:](https://rubygems.org/gems/hobo), [:book:](http://rubydoc.info/gems/hobo)
57
+ - [News & Updates](http://hobocentral.net/blog)
58
+
59
+ Future:
60
+
61
+ - [Trailblazer](http://trailblazerb.org), [:octocat:](https://github.com/apotonick/trailblazer), [:gem:](https://rubygems.org/gems/trailblazer), [:book:](http://rubydoc.info/gems/trailblazer) - a thin layer on top of rails - (gently) enforces encapsulation, a "more" intuitive code structure and giving you a "better" object-oriented architecture by Nick Sutterer et al
62
+
63
+
64
+
65
+ ## Sinatra
66
+
67
+ _Micro Framework_
68
+
69
+ - [Sinatra HQ](http://sinatrarb.com) - [:octocat:](https://github.com/sinatra), [:gem:](https://rubygems.org/gems/sinatra), [:book:](http://rubydoc.info/gems/sinatra)
70
+
71
+ Extensions:
72
+
73
+ - [Padrino HQ](http://padrinorb.com) - [:octocat:](https://github.com/padrino), [:gem:](https://rubygems.org/gems/padrino), [:book:](http://rubydoc.info/gems/padrino)
74
+ - [News & Updates](http://www.padrinorb.com/blog)
75
+
76
+ Fun / Hack:
77
+
78
+ - [Almost Sinatra :octocat:](https://github.com/rkh/almost-sinatra) - Sinatra refactored, only six lines of code by Konstantin Haase
79
+
80
+ Future:
81
+
82
+ - [Mustermann](http://rkh.github.io/mustermann), [:octocat:](https://github.com/rkh/mustermann) - your personal string matching expert; can be used as a plugin for Sinatra 1.x and will power Sinatra 2.0; by Konstantin Haase et al
83
+
84
+
85
+ ## Volt
86
+
87
+ _Client/Server Isomorphic Framework_
88
+
89
+ - [Volt HQ](http://voltframework.com) - [:octocat:](https://github.com/voltrb), [:gem:](https://rubygems.org/gems/volt), [:book:](http://rubydoc.info/gems/volt)
90
+ - [News & Updates](http://voltframework.com/blog)
91
+
92
+ ## Async Web (Socket) Frameworks
93
+
94
+ - [Cramp :octocat:](https://github.com/lifo/cramp), [:gem:](https://rubygems.org/gems/cramp) - a fully asynchronous realtime web application framework built on top of event machine; providing full-duplex bi-directional communication by Pratik Naik
95
+
96
+ - [Lattice :octocat:](https://github.com/celluloid/lattice), [:gem:](https://rubygems.org/gems/lattice), [:book:](http://rubydoc.info/gems/lattice) - an actor-based web framework built on top of celluloid, reel, and webmachine; designed for realtime apps, end-to-end streaming, and websockets by Tony Arcieri et al
97
+
98
+
99
+
100
+ ## Web Service Frameworks
101
+
102
+ _JSON HTTP API Builder_
103
+
104
+ - [Grape](http://intridea.github.io/grape) - [:octocat:](https://github.com/intridea/grape), [:gem:](https://rubygems.org/gems/grape), [:book:](http://rubydoc.info/gems/grape) - a micro-framework for creating REST-like APIs
105
+ - [Crêpe :octocat:](https://github.com/crepe) - [:gem:](https://rubygems.org/gems/crepe) - a thin API stack
106
+ - [Yaks :octocat:](https://github.com/plexus/yaks) - [:gem:](https://rubygems.org/gems/yaks), [:book:](http://rubydoc.info/gems/yaks) - serialize to hypermedia. HAL, JSON API, HALO, collection+JSON etc. by Arne Brasseur et al
107
+ - [Praxis](http://praxis-framework.io) - [:octocat:](https://github.com/rightscale/praxis), [:gem:](https://rubygems.org/gems/praxis), [:book:](http://rubydoc.info/gems/praxis) - a micro framework focusing on the design and coding aspects of creating good APIs quick by Josep M. Blanquer et al
108
+
109
+ ## Micro Framework Alternatives
110
+
111
+ - [Rum :octocat:](https://github.com/chneukirchen/rum) - gRand Unified Mapper for rack apps by Christian Neukirchen
112
+ - [Cuba](http://cuba.is) - [:octocat:](https://github.com/soveran/cuba), [:gem:](https://rubygems.org/gems/cuba), [:book:](http://rubydoc.info/gems/cuba) - tiny but powerful mapper for rack apps by Michel Martens
113
+ - [New York, New York (NYNY)](http://alisnic.github.io/nyny) - [:octocat:](https://github.com/alisnic/nyny), [:gem:](https://rubygems.org/gems/nyny), [:book:](http://rubydoc.info/gems/nyny) - a tiny (~300 lines of code) web framework on top of rack by Andrei Lisnic
114
+ - [Roda](http://roda.jeremyevans.net) - [:octocat:](https://github.com/jeremyevans/roda), [:gem:](https://rubygems.org/gems/roda), [:book:](http://rubydoc.info/gems/roda) - a routing tree web framework toolkit by Jeremy Evans
115
+ - [Hobbit :octocat:](https://github.com/patriciomacadden/hobbit), [:gem:](https://rubygems.org/gems/hobbit), [:book:](http://rubydoc.info/gems/hobbit) - a minimalistic microframework built on top of rack by Patricio Mac Adden
116
+ - [Brooklyn :octocat:](https://github.com/luislavena/brooklyn) - a small web tool on top of rack by Luis Lavena
117
+ - [Nancy](http://guilleiguaran.github.io/nancy), [:octocat:](https://github.com/guilleiguaran/nancy), [:gem:](https://rubygems.org/gems/nancy), [:book:](http://rubydoc.info/gems/nancy) - Sinatra's little daughter by Guillermo Iguaran
118
+ - [Camping](http://camping.io), [:octocat:](https://github.com/camping), [:gem:](https://rubygems.org/gems/camping), [:book:](http://www.rubydoc.info/gems/camping) - minature rails for stay-at-home moms; the 4k pocket full-of-gags web microframework
119
+ - [Scorched](http://scorchedrb.com), [:octocat:](https://github.com/Wardrop/Scorched), [:gem:](https://rubygems.org/gems/scorched), [:book:](http://rubydoc.info/gems/scorched) - light-weight, DRY as a desert, web framework by Tom Wardrop et al
120
+
121
+
122
+ <!--
123
+ more
124
+ Kenji - https://github.com/kballenegger/kenji ??
125
+ -->
126
+
127
+
128
+
129
+ ## "Full Stack" Macro Framework Alternatives
130
+
131
+ - [Lotus HQ](http://lotusrb.org) - [:octocat:](https://github.com/lotus), [:gem:](https://rubygems.org/gems/lotusrb), [:book:](http://rubydoc.info/gems/lotusrb) - a complete web framework; bringing back object-oriented programming to web development, leveraging a stable API, minimal DSL and plain objects by Luca Guidi et al
132
+ - [News & Updates](http://lotusrb.org/blog)
133
+
134
+ <!-- new list -->
135
+
136
+ - [Pakyow HQ](http://pakyow.org) - [:octocat:](https://github.com/pakyow), [:gem:](https://rubygems.org/gems/pakyow) - an open-source framework for the modern web with a view-first development process that's friendly to everyone whether you're a designer or a developer
137
+ - [News & Updates](http://pakyow.org/blog)
138
+
139
+ <!-- new list -->
140
+
141
+ - [Ramaze HQ](http://ramaze.net) - [:octocat:](https://github.com/Ramaze), [:gem:](https://rubygems.org/gems/ramaze), [:book:](http://rubydoc.info/gems/ramaze) - a simple, light and modular open-source web application framework by Michael Fellinger et al
142
+ - [News & Updates](http://ramaze.net/blog)
143
+
144
+ ## Thanks
145
+
146
+ Josep M. Blanquer
147
+
148
+ ## Meta
149
+
150
+ **License**
151
+
152
+ The awesome list is dedicated to the public domain. Use it as you please with no restrictions whatsoever.
153
+
154
+ **Questions? Comments?**
155
+
156
+ Send them along to the ruby-talk mailing list. Thanks!
157
+
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ ## minitest setup
5
+ require 'minitest/autorun'
6
+
7
+ ## our own code
8
+ require 'catalogdb'
9
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catalogdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -137,7 +137,10 @@ files:
137
137
  - README.md
138
138
  - Rakefile
139
139
  - lib/catalogdb.rb
140
+ - lib/catalogdb/reader.rb
140
141
  - lib/catalogdb/version.rb
142
+ - test/data/RUBY.md
143
+ - test/helper.rb
141
144
  - test/test_reader.rb
142
145
  - test/test_version.rb
143
146
  homepage: https://github.com/textkit/catalog.db