Sha256: 852da7588a4ab8d5b863c87abb5e4ddbe0c3903011b31f49216f0bc259cd8350
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
require 'nokogiri' module Hatenablog class Category # Create a new blog categories from a XML string. # @param [String] xml XML string representation # @return [Hatenablog::Category] def self.load_xml(xml) Hatenablog::Category.new(xml) end # @return [Array] def categories @categories.dup end def each(&block) return enum_for(__method__) unless block_given? @categories.each do |category| block.call(category) end end # If fixed, only categories in this categories can be used for a blog entry. # @return [Boolean] def fixed? @fixed == 'yes' end private def initialize(xml) @document = Nokogiri::XML(xml) parse_document end def parse_document @categories = @document.css('atom|category').inject([]) do |categories, category| categories << category['term'].to_s end @fixed = @document.at_css('app|categories')['fixed'].to_s @fixed = 'no' if @fixed.nil? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hatenablog-0.7.0 | lib/hatenablog/category.rb |
hatenablog-0.6.0 | lib/hatenablog/category.rb |