class Hatenablog::Category

Public Class Methods

load_xml(xml) click to toggle source

Create a new blog categories from a XML string. @param [String] xml XML string representation @return [Hatenablog::Category]

# File lib/hatenablog/category.rb, line 9
def self.load_xml(xml)
  Hatenablog::Category.new(xml)
end
new(xml) click to toggle source
# File lib/hatenablog/category.rb, line 36
def initialize(xml)
  @document = Nokogiri::XML(xml)
  parse_document
end

Public Instance Methods

categories() click to toggle source

@return [Array]

# File lib/hatenablog/category.rb, line 14
def categories
  @categories.dup
end
each(&block) click to toggle source
# File lib/hatenablog/category.rb, line 18
def each(&block)
  return enum_for unless block_given?

  @categories.each do |category|
    # @type var block: ^(String) -> void
    block.call(category)
  end
end
fixed?() click to toggle source

If fixed, only categories in this categories can be used for a blog entry. @return [Boolean]

# File lib/hatenablog/category.rb, line 29
def fixed?
  @fixed == 'yes'
end

Private Instance Methods

parse_document() click to toggle source
# File lib/hatenablog/category.rb, line 41
def parse_document
  @categories = @document.css('atom|category').inject(Array.new) do |categories, category|
    categories << category['term'].to_s
  end

  @fixed = @document.at_css('app|categories')['fixed'].to_s
  @fixed = 'no' if @fixed.nil?
end