smg 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,3 +1,70 @@
1
+ == DESCRIPTION:
2
+
3
+ XML to Object mapping library with simple declarative syntax.
4
+ Backed by Nokogiri's SAX Parser.
5
+
6
+ == FEATURES:
7
+
8
+ * Typecasting
9
+ * Nested resources (aka has_one)
10
+ * Collections (aka has_many)
11
+
12
+ == EXAMPLES:
13
+
14
+ === Twitter
15
+
16
+ class Status
17
+ include SMG::Resource
18
+
19
+ root 'status'
20
+
21
+ extract :id , :class => :integer, :as => :status_id
22
+ extract :created_at , :class => :datetime
23
+ extract :text
24
+
25
+ end
26
+
27
+ class User
28
+ include SMG::Resource
29
+
30
+ root 'user'
31
+
32
+ extract :id , :class => :integer, :as => :twitter_id
33
+ extract :location , :class => :string
34
+ extract :status , :class => Status
35
+ extract :created_at , :class => :datetime
36
+ extract :name
37
+ extract :screen_name
38
+
39
+ end
40
+
41
+ === discogs.com
42
+
43
+ class Label
44
+
45
+ class Release
46
+
47
+ include SMG::Resource
48
+
49
+ extract :release , :at => :id, :as => :discogs_id, :class => :integer
50
+ extract :release , :at => :status
51
+
52
+ root 'release'
53
+ extract :title
54
+ extract :catno
55
+ extract :artist
56
+
57
+ end
58
+
59
+ include SMG::Resource
60
+
61
+ root 'resp/label'
62
+ extract :name
63
+ extract :profile
64
+ collect 'releases/release' , :as => :releases, :class => Release
65
+
66
+ end
67
+
1
68
  == REQUIREMENTS:
2
69
 
3
70
  nokogiri (>=1.3)
@@ -6,7 +73,7 @@ nokogiri (>=1.3)
6
73
 
7
74
  (The MIT License)
8
75
 
9
- Copyright (c) 2009
76
+ Copyright (c) 2010
10
77
 
11
78
  Permission is hereby granted, free of charge, to any person obtaining
12
79
  a copy of this software and associated documentation files (the
data/lib/smg/mapping.rb CHANGED
@@ -13,9 +13,9 @@ module SMG #:nodoc:
13
13
  def attach_element(tag,options)
14
14
  chain = handle_path(tag)
15
15
  if options.key?(:at)
16
- ele = Element.new(chain, options)
16
+ thing = Element.new(chain, options)
17
17
  @attributes[chain] ||= {}
18
- @attributes[chain][ele.at] = ele
18
+ @attributes[chain][thing.at] = thing
19
19
  else
20
20
  @elements[chain] = Element.new(chain, options)
21
21
  end
@@ -27,8 +27,7 @@ module SMG #:nodoc:
27
27
  end
28
28
 
29
29
  def use_root(path)
30
- raise "root already defined!" if @root
31
- @root = normalize_path(path)
30
+ @root = normalize_path(path) # just a root tag for further definitions
32
31
  end
33
32
 
34
33
  private
@@ -33,7 +33,7 @@ module SMG #:nodoc:
33
33
  def cast(value)
34
34
  @cast_to ? ::SMG::Mapping::TypeCasts[@cast_to, value] : value
35
35
  rescue
36
- #TODO: report about malformed data
36
+ raise ArgumentError, "#{value.inspect} is not a valid source for #{@cast_to.inspect}"
37
37
  end
38
38
 
39
39
  def collection?
data/lib/smg/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module SMG
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
4
4
 
5
5
  # EOF
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - SSDany
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-16 00:00:00 +04:00
17
+ date: 2010-04-17 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,10 @@ dependencies:
30
30
  version: "1.3"
31
31
  type: :runtime
32
32
  version_requirements: *id001
33
- description: Simple declaratibve XML parsing library. Backed by Nokogiri
33
+ description: |
34
+ Object to xml mapping library with simple declarative syntax.
35
+ Backed by Nokogiri's SAX Parser.
36
+
34
37
  email: inadsence@gmail.com
35
38
  executables: []
36
39