File: simple.rb

package info (click to toggle)
ruby-sawyer 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 280 kB
  • sloc: ruby: 1,224; sh: 17; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 594 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Sawyer
  module LinkParsers

    class Simple

      LINK_REGEX = /_?url$/


      # Public: Parses simple *_url style links on resources
      #
      # data   - Hash of resource data
      #
      # Returns a Hash of data with separate links Hash
      def parse(data)

        links = {}
        inline_links = data.keys.select {|k| k.to_s[LINK_REGEX] }
        inline_links.each do |key|
          rel_name = key.to_s == 'url' ? 'self' : key.to_s.gsub(LINK_REGEX, '')
          links[rel_name.to_sym] = data[key]
        end

        return data, links
      end

    end

  end
end