Class: UniversalDetector::EscCharSetProber

Inherits:
CharSetProber show all
Defined in:
lib/EscCharSetProber.rb

Instance Method Summary collapse

Methods inherited from CharSetProber

#filter_high_bit_only, #filter_with_english_letters, #filter_without_english_letters, #get_state

Constructor Details

#initializeEscCharSetProber

Returns a new instance of EscCharSetProber.



36
37
38
39
40
41
42
43
44
45
# File 'lib/EscCharSetProber.rb', line 36

def initialize
    super
    @_mCodingSM = [ \
        CodingStateMachine(HZSMModel),
        CodingStateMachine(ISO2022CNSMModel),
        CodingStateMachine(ISO2022JPSMModel),
        CodingStateMachine(ISO2022KRSMModel)
        ]
    reset()
end

Instance Method Details

#feed(aBuf) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/EscCharSetProber.rb', line 70

def feed(aBuf)
    for c in aBuf
        for codingSM in @_mCodingSM
            unless codingSM then continue end
            unless codingSM.active then continue end
            codingState = codingSM.next_state(c)
            if codingState == :Error
                codingSM.active = false
                @_mActiveSM -= 1
                if @_mActiveSM <= 0
                    @_mState = :NotMe
                    return get_state()
                end
            elsif codingState == :ItsMe
                @_mState = :FoundIt
                @_mDetectedCharset = codingSM.get_coding_state_machine()
                return get_state()
            end
        end
    end

    return get_state()
end

#get_charset_nameObject



58
59
60
# File 'lib/EscCharSetProber.rb', line 58

def get_charset_name
    return @_mDetectedCharset
end

#get_confidenceObject



62
63
64
65
66
67
68
# File 'lib/EscCharSetProber.rb', line 62

def get_confidence
    if @_mDetectedCharset
        return 0.99
    else
        return 0.00
    end
end

#resetObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/EscCharSetProber.rb', line 47

def reset
    super
    for codingSM in @_mCodingSM
        unless codingSM then continue end
        codingSM.active = true
        codingSM.reset()
    end
    @_mActiveSM = @_mCodingSM.length
    @_mDetectedCharset = nil
end